Pyramid, Python3, SQLAlchemy and MySQL - mysql

I want Pyramid, Python3, SQLAlchemy and MySQL to play nice on a single machine. This question has been asked before, but it was a long enough time ago that I'm hoping the answer has changed...
Questions:
What driver works for getting a Python 3 Pyramid app to talk nicely to MySQL via SQLAalchemy? Is this even possible?
I've gotten quite far in this project thinking it would be a simple thing to switch out databases, now I'm a bit stuck and downgrading to Python 2.7 is not something I want to have to go through. So my second question is:
If there is no way to talk to MySQL nicely without downgrading, is there a database that Python 3 is ready for (besides SQLite)?
Or lastly, how would I overcome any of the problems mentioned in the 'Stuff I've Tried' section below?
Stuff I've Tried:
PyMySQL
I have PyMySQL installed and I even got it to complain about incorrect passwords and a missing database so it's getting something right. But when I tried to initialize my database (using initialize_foo_db) everything went sour:
2013-02-06 17:18:31,282 INFO [sqlalchemy.engine.base.Engine][MainThread] b'SELECT DATABASE()'
2013-02-06 17:18:31,282 INFO [sqlalchemy.engine.base.Engine][MainThread] ()
Traceback (most recent call last):
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/pool.py", line 719, in _do_get
return self._pool.get(wait, self._timeout)
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/util/queue.py", line 137, in get
raise Empty
sqlalchemy.util.queue.Empty
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "../bin/initialize_mega_db", line 9, in <module>
load_entry_point('mega==0.0', 'console_scripts', 'initialize_mega_db')()
File "/home/sheena/MegaCatalogue/env/mega/mega/scripts/initializedb.py", line 46, in main
Base.metadata.create_all(engine)
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/schema.py", line 2567, in create_all
tables=tables)
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/engine/base.py", line 2301, in _run_visitor
conn = self.contextual_connect(close_with_result=False)
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/engine/base.py", line 2492, in contextual_connect
self.pool.connect(),
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/pool.py", line 224, in connect
return _ConnectionFairy(self).checkout()
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/pool.py", line 387, in __init__
rec = self._connection_record = pool._do_get()
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/pool.py", line 741, in _do_get
con = self._create_connection()
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/pool.py", line 188, in _create_connection
return _ConnectionRecord(self)
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/pool.py", line 273, in __init__
pool.dispatch.first_connect.exec_once(self.connection, self)
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/event.py", line 279, in exec_once
self(*args, **kw)
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/event.py", line 288, in __call__
fn(*args, **kw)
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/engine/strategies.py", line 168, in first_connect
dialect.initialize(c)
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/dialects/mysql/base.py", line 1999, in initialize
default.DefaultDialect.initialize(self, connection)
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/engine/default.py", line 177, in initialize
self._get_default_schema_name(connection)
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/dialects/mysql/base.py", line 1964, in _get_default_schema_name
return connection.execute('SELECT DATABASE()').scalar()
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/engine/base.py", line 1449, in execute
params)
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/engine/base.py", line 1628, in _execute_text
statement, parameters
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/engine/base.py", line 1691, in _execute_context
context)
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/SQLAlchemy-0.7.8-py3.2.egg/sqlalchemy/engine/default.py", line 333, in do_execute
cursor.execute(statement, parameters)
File "/home/sheena/MegaCatalogue/env/local/lib/python3.2/site-packages/PyMySQL3-0.5-py3.2.egg/pymysql/cursors.py", line 108, in execute
query = query % escaped_args
TypeError: unsupported operand type(s) for %: 'bytes' and 'tuple'
oursql
I tried installing oursql using pip install -r file
where file contains:
#oursql==0.9.3 but need special Python 3 build https://bugs.launchpad.net/oursql/+bug/1051512
https://launchpad.net/oursql/py3k/py3k-0.9.3/+download/oursql-0.9.3.zip
pyramid==1.3.4
And I got:
oursqlx/compat.h:13:19: fatal error: mysql.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
myconnpy
This installs without error but I can't seem to find out what I should tell SQLAlchemy to look for. In the appropriate settings.ini file I have tried:
sqlalchemy.url = mysql+myconnpy://...
as well as a bunch of other things. Google is failing me on this one...
UPDATE - a semblance of progress
I've managed to install oursql build dependencies:
sudo aptitude install python-pip libmysqlclient-dev
I then downloaded oursql0.9.3 and ran:
setup.py install
The output was this:
cython not found, using previously-cython'd .c file.
running install
running build
running build_ext
running install_lib
copying build/lib.linux-x86_64-3.2/oursql.cpython-32mu.so -> /home/sheena/MegaCatalogue/env/lib/python3.2/site-packages
running install_egg_info
Writing /path/to/virtualenv/foo/lib/python3.2/site-packages/oursql-0.9.3.egg-info
I opened a shell and apparently the module doesn't exist - it can't be imported anyway. But for some reason it is listed if I say help() then modules

Related

Failed to create GLFW Window while trying to run Mujoco (UBUNTU)

So, I am trying to install, and run Mujoco-py on my ubuntu. Everything went well but, I cant install the libglew1.5. I searche for it in the Ubuntu Package Archives, but no luck. Then I skipped that part, but when im trying to run the example its giving me this error.
(mujoco_py) user#user:~/.mujoco/mujoco-py/examples$ python3 setting_state.py
Creating window glfw
libEGL warning: MESA-LOADER: failed to open iris: /usr/lib/dri/iris_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
libEGL warning: MESA-LOADER: failed to open swrast: /usr/lib/dri/swrast_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
GLFW error (code %d): %s 65542 b'EGL: Failed to initialize EGL: EGL is not or could not be initialized'
Traceback (most recent call last):
File "setting_state.py", line 32, in <module>
viewer = MjViewer(sim)
File "/home/sazzad14/.mujoco/mujoco-py/mujoco_py/mjviewer.py", line 137, in __init__
super().__init__(sim)
File "/home/sazzad14/.mujoco/mujoco-py/mujoco_py/mjviewer.py", line 28, in __init__
super().__init__(sim)
File "mjrendercontext.pyx", line 311, in mujoco_py.cymj.MjRenderContextWindow.__init__
File "mjrendercontext.pyx", line 46, in mujoco_py.cymj.MjRenderContext.__init__
File "mjrendercontext.pyx", line 102, in mujoco_py.cymj.MjRenderContext._setup_opengl_context
File "opengl_context.pyx", line 48, in mujoco_py.cymj.GlfwContext.__init__
File "opengl_context.pyx", line 99, in mujoco_py.cymj.GlfwContext._create_window
mujoco_py.cymj.GlfwError: Failed to create GLFW window
I installed libglew2.2, but that does not help.

Unable to start rst2html5slides after installation

We are using Powerpoint and Restructured Text together with Python-Sphinx. I was asking myself, if it is possible to create slides using ReST.
I found the interesting Tool rst2html5slides on
https://rst2html5slides.readthedocs.io/en/latest/index.html.
I installed the tool with:
pip install rst2html5slides
This worked without problems.
Now, I was unable to use the tool. Typing rst2html5slides on my console gives:
Traceback (most recent call last):
File "c:\python27\lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "c:\python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Python27\Scripts\rst2html5slides.exe\__main__.py", line 5, in <module>
File "c:\python27\lib\site-packages\rst2html5slides.py", line 16, in <module>
from rst2html5 import HTML5Translator, HTML5Writer
ImportError: No module named rst2html5
Typing pip list issues:
rst2html5 1.9.4
rst2html5slides 1.0
After inspecting my c:\python27\lib\site-packages\ directory I found out, that there is an rst2html5slides_.py, but no rst2html5slides.py. So I tried to just rename this file.
No it was possible for me to start rst2html5slides --traceback presentation.txt simple_deck.html, but I just have another problem.
Traceback (most recent call last):
File "c:\python27\lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "c:\python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Python27\Scripts\rst2html5slides.exe\__main__.py", line 9, in <module>
File "c:\python27\lib\site-packages\rst2html5slides.py", line 484, in main
publish_cmdline(writer=SlideWriter(), description=description)
File "c:\python27\lib\site-packages\docutils\core.py", line 352, in publish_cmdline
config_section=config_section, enable_exit_status=enable_exit_status)
File "c:\python27\lib\site-packages\docutils\core.py", line 219, in publish
output = self.writer.write(self.document, self.destination)
File "c:\python27\lib\site-packages\docutils\writers\__init__.py", line 80, in write
self.translate()
File "c:\python27\lib\site-packages\rst2html5slides.py", line 200, in translate
HTML5Writer.translate(self)
File "c:\python27\lib\site-packages\rst2html5.py", line 227, in translate
self.document.walkabout(visitor)
File "c:\python27\lib\site-packages\docutils\nodes.py", line 187, in walkabout
visitor.dispatch_departure(self)
File "c:\python27\lib\site-packages\docutils\nodes.py", line 1895, in dispatch_departure
return method(node)
File "c:\python27\lib\site-packages\rst2html5slides.py", line 294, in depart_document
self._ordered_tag_attributes(deck,
AttributeError: SlideTranslator instance has no attribute '_ordered_tag_attributes'
AttributeError: SlideTranslator instance has no attribute '_ordered_tag_attributes'
Exiting due to error. Use "--traceback" to diagnose.
Please report errors to <docutils-users#lists.sf.net>.
Include "--traceback" output, Docutils version (0.12 [release]),
Python version (2.7.10), your OS type & version, and the
command line used.
What I'm doing wrong here?
rst2html5slides' author here. I've updated the package a while ago. Please, update it and it should run.

Python unable to detect file, throws an error

I run a cocos2dx to generate an APK file, but it throws out this error
BUILD SUCCESSFUL in 7m 49s
54 actionable tasks: 3 executed, 51 up-to-date
Traceback (most recent call last):
File "/cocos2dx/tools/cocos2d-console/bin/cocos.py", line 1072, in <module>
run_plugin(command, argv, plugins)
File "/cocos2dx/tools/cocos2d-console/bin/cocos.py", line 961, in run_plugin
plugin.run(argv, dependencies_objects)
File "/cocos2dx/tools/cocos2d-console/plugins/plugin_compile/project_compile.py", line 1646, in run
self.build_android()
File "/cocos2dx/tools/cocos2d-console/plugins/plugin_compile/project_compile.py", line 581, in build_android
self.apk_path = builder.do_build_apk(build_mode, self._no_apk, output_dir, self._custom_step_args, self._ap, self)
File "/cocos2dx/tools/cocos2d-console/plugins/plugin_compile/build_android.py", line 669, in do_build_apk
shutil.copy(gen_apk_path, output_dir)
File "/usr/lib/python2.7/shutil.py", line 119, in copy
copyfile(src, dst)
File "/usr/lib/python2.7/shutil.py", line 82, in copyfile
with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: '/project/Cocos2dx/proj.android-studio/app/build/outputs/apk/Cocos2dx-debug.apk
Any idea what could be the issue?
You should use Android Studio (instead of run the python function to call ANT) to build the project to apk. It's far easier use, trace error and debug.
about your question:
/project/Cocos2dx/proj.android-studio/app/build/outputs/apk/Cocos2dx-debug.apk
this path is belong to project Android Studio. In my experience, when using the cocos console command, it use proj.android instead of proj.android-studio

Get rid of pyximport

I'm trying to use Cython. I use setup.py and build as opposed to letting pyximport do this. However, every time I import my module it seems pyximport is called. Pyximport fails to build and everything crashes.
I use Spyder. I do not have a single reference to pyximport in my project, but Spyder does not seem to care and keeps calling pyximprot.
I called my program from the command window (outside Spyder) and it ran just fine.
How can i get rid of the call to pyximport? Or is something else going on?
import c_result
Traceback (most recent call last):
File "<ipython-input-2-3e92d1c50179>", line 1, in <module>
import c_result
File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyximport\pyximport.py", line 458, in load_module
language_level=self.language_level)
File "C:\Users\xxxR\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyximport\pyximport.py", line 231, in load_module
raise exc.with_traceback(tb)
File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyximport\pyximport.py", line 215, in load_module
inplace=build_inplace, language_level=language_level)
File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyximport\pyximport.py", line 191, in build_module
reload_support=pyxargs.reload_support)
File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\pyximport\pyxbuild.py", line 102, in pyx_to_dll
dist.run_commands()
File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\Cython\Distutils\old_build_ext.py", line 185, in run
_build_ext.build_ext.run(self)
File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\distutils\command\build_ext.py", line 339, in run
self.build_extensions()
File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\Cython\Distutils\old_build_ext.py", line 192, in build_extensions
ext.sources = self.cython_sources(ext.sources, ext)
File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\site-packages\Cython\Distutils\old_build_ext.py", line 327, in cython_sources
self.mkpath(os.path.dirname(target))
File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\distutils\cmd.py", line 338, in mkpath
dir_util.mkpath(name, mode, dry_run=self.dry_run)
File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\distutils\dir_util.py", line 74, in mkpath
"could not create '%s': %s" % (head, exc.args[-1]))
ImportError: Building module c_result failed: ["distutils.errors.DistutilsFileError: could not create 'C:\\Windows\\system32\\config\\systemprofile': Kan ikke opprette en fil når filen allerede finnes\n"]
The problem appeared in Spyder because the package's initialization actually loads pyximport and calls pyximport.install(), in the file utils/site/sitecustomize.py.
Other have complained about it on GitHub:
spyder issue #5299
spyder issue #5087
A solution that is not elegant (will not survive updates of spyder, for instance) but that should work is to manually edit the sitecustomize.py file in your spyder installation and remove the section under if HAS_PYXIMPORT:
(Spyder maintainer here) This problem was fixed in our 3.2.8 version, released on March 2018.

SQLAlchemy mysql dialect error with py2app

I'm having trouble getting SQLAlchemy to work with my compiled app after getting through py2app. I've done this successfully in Windows with py2exe. The following is my setup file:
APP = ['Blah.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True,
'includes': ['sip',
'PyQt4._qt',
'sqlalchemy.dialects.mysql',
'MySQLdb',
"gzip"]
}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
This appears like it's the right way to do it, as I've seen people use it for sqlite, however I still get this error upon trying to run the app after compile:
sqlalchemy.exc.ArgumentError: Could not determine dialect for 'mysql+mysqldb'
I've recently been trying with PyInstaller and have gotten stuck at pretty much the same spot, albeit with a different error which is the following:
Traceback (most recent call last):
File "<string>", line 96, in <module>
File "/Users/tom/Downloads/pyinstaller-pyinstaller-2145d84/PyInstaller/loader/iu.py", line 386, in importHook
mod = _self_doimport(nm, ctx, fqname)
File "/Users/tom/Downloads/pyinstaller-pyinstaller-2145d84/PyInstaller/loader/iu.py", line 480, in doimport
exec co in mod.__dict__
File "build/bdist.macosx-10.7-intel/egg/MySQLdb/__init__.py", line 19, in <module>
File "/Users/tom/Downloads/pyinstaller-pyinstaller-2145d84/PyInstaller/loader/iu.py", line 386, in importHook
mod = _self_doimport(nm, ctx, fqname)
File "/Users/tom/Downloads/pyinstaller-pyinstaller-2145d84/PyInstaller/loader/iu.py", line 480, in doimport
exec co in mod.__dict__
File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in <module>
File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 4, in __bootstrap__
File "OSX_Installer/Jango/build/pyi.darwin/Jango/out00-PYZ.pyz/pkg_resources", line 882, in resource_filename
File "OSX_Installer/Jango/build/pyi.darwin/Jango/out00-PYZ.pyz/pkg_resources", line 1352, in get_resource_filename
File "OSX_Installer/Jango/build/pyi.darwin/Jango/out00-PYZ.pyz/pkg_resources", line 1363, in _extract_resource
KeyError: '_mysql/_mysql.so'
you probably also need _mysql which should include the native mysql bindings. also, this bindings need the binary mysql libraries to be installed on the target system.
your application would probably be a lot more portable if you used a pure python mysql library, such as pymysql or MySQL Connector/Python (both are supported by sqlalchemy)