I am using Pyinstaller to compile Python to a standalone executable. The sourcecode includes modules PySide and SqlAlchemy. The dist .exe that PyInstaller creates runs OK, but when I run commands that access the database I get this error code in the command prompt:
Traceback (most recent call last):
File "clipper_tree.py", line 1907, in add_tree
File "build\bdist.win-amd64\egg\sqlalchemy\sql\operators.py", line 304, in __eq__
File "build\bdist.win-amd64\egg\sqlalchemy\orm\attributes.py", line 175, in operate
File "build\bdist.win-amd64\egg\sqlalchemy\sql\operators.py", line 304, in __eq__
File "build\bdist.win-amd64\egg\sqlalchemy\orm\properties.py", line 270, in operate
File "build\bdist.win-amd64\egg\sqlalchemy\sql\annotation.py", line 95, in __eq__
File "build\bdist.win-amd64\egg\sqlalchemy\sql\operators.py", line 304, in __eq__
File "build\bdist.win-amd64\egg\sqlalchemy\sql\elements.py", line 686, in operate
File "build\bdist.win-amd64\egg\sqlalchemy\sql\operators.py", line 304, in __eq__
File "<string>", line 1, in <lambda>
File "build\bdist.win-amd64\egg\sqlalchemy\sql\type_api.py", line 62, in operate
File "build\bdist.win-amd64\egg\sqlalchemy\util\langhelpers.py", line 964, in __getattr__
File "build\bdist.win-amd64\egg\sqlalchemy\util\langhelpers.py", line 962, in __getattr__
ImportError: Could not resolve module sqlalchemy.sql.default_comparator
While compiling, the command prompt output a few warnings about not being able to find "hidden DLLs" relating to sql alchemy. It said it was removing sqlalchemy/test files in response. Any help here would be deeply appreciated.
i had a same issue earlier.. resolves this problem by importing sqlalchemy.sql.default_comparator on my main program..
As #fredpi says you can add the module to the hiddenimports parameter of the Analysis initializer in the .spec file of the python file your trying to compile. Like so: hiddenimports=['sqlalchemy.sql.default_comparator']
Make sure you pass the .spec file when you run pyinstaller, or it will overwrite the .spec file and your changes will be lost. For example: pyinstaller --onefile myscript.spec
Related
I need to compile a standalone executive or --onedir version of it for my Kivy application for Windows using PyInstaller. I experience problems one after another, and this is why I post it here. I can find solutions for almost all of them, but it seems that something goes wrong from the beginning.
The program consists of .py and .kv file, requires (apart from Kivy modules) only Textract (imported as txt) and works perfectly if I use shell of IDLE.
I use the latest versions of Kivy and PyInstaller (in case if PyInstaller I also tried developer version, as some people suggested).
The first problem I encounter is
ModuleNotFoundError: No module named 'pkg_resources.py2_warn'
[4808] Failed to execute script pyi_rth_pkgres
which I solve with
pyinstaller wordcount.py --hiddenimport pkg_resources.py2_warn
as some people suggested to deal with this issue before. Then, full of pleasant expectations, I run the .exe again and get this:
FileNotFoundError: [Errno 2] No such file or directory: 'wordcount.kv'
[3356] Failed to execute script wordcount
Obviously, the .kv was somehow not included in the package, okay, I change my command again:
pyinstaller wordcount.py --add-data "./wordcount.kv;." --hiddenimport pkg_resources.py2_warn
manually forcing the .kv into package. Or I could just copy it there - with the same result:
[WARNING] [Image ] Unable to load image <C:\GUI Projects\wordcount\dist\wordcount\kivy_install\data\glsl\default.png>
[CRITICAL] [Window ] Unable to find any valuable Window provider. Please enable debug logging (e.g. add -d if running from the command line, or change the log level in the config) and re-run your app to identify potential causes
sdl2 - Exception: SDL2: Unable to load image
File "site-packages\kivy\core\__init__.py", line 71, in core_select_lib
File "site-packages\kivy\core\window\window_sdl2.py", line 152, in __init__
File "site-packages\kivy\core\window\__init__.py", line 981, in __init__
File "site-packages\kivy\core\window\window_sdl2.py", line 312, in create_window
File "site-packages\kivy\core\window\__init__.py", line 1258, in create_window
File "kivy\graphics\instructions.pyx", line 783, in kivy.graphics.instructions.RenderContext.__init__
File "site-packages\kivy\core\image\__init__.py", line 561, in __init__
File "site-packages\kivy\core\image\__init__.py", line 756, in _set_filename
File "site-packages\kivy\core\image\__init__.py", line 460, in load
File "site-packages\kivy\core\image\__init__.py", line 223, in __init__
File "site-packages\kivy\core\image\img_sdl2.py", line 47, in load
[CRITICAL] [App ] Unable to get a Window, abort.
as people suggest, onw may just copy .dlls to the directory ([Dist]\\libpng16-16.dll). Or to rewrite spec. like this:
... regrettably, without any positive result.
Traceback (most recent call last):
File "wordcount.py", line 47, in <module>
WordCount().run()
File "site-packages\kivy\app.py", line 855, in run
File "site-packages\kivy\base.py", line 504, in runTouchApp
File "site-packages\kivy\core\window\window_sdl2.py", line 747, in mainloop
File "site-packages\kivy\core\window\window_sdl2.py", line 479, in _mainloop
File "site-packages\kivy\base.py", line 339, in idle
File "site-packages\kivy\clock.py", line 591, in tick
File "kivy\_clock.pyx", line 384, in kivy._clock.CyClockBase._process_events
File "kivy\_clock.pyx", line 414, in kivy._clock.CyClockBase._process_events
File "kivy\_clock.pyx", line 412, in kivy._clock.CyClockBase._process_events
File "kivy\_clock.pyx", line 167, in kivy._clock.ClockEvent.tick
File "site-packages\kivy\uix\filechooser.py", line 698, in _update_files
File "site-packages\kivy\uix\filechooser.py", line 718, in _create_files_entries
File "site-packages\kivy\uix\filechooser.py", line 839, in _generate_file_entries
File "site-packages\kivy\uix\filechooser.py", line 871, in _add_files
File "site-packages\kivy\uix\filechooser.py", line 871, in <listcomp>
File "site-packages\kivy\uix\filechooser.py", line 178, in is_hidden
ModuleNotFoundError: No module named 'win32timezone'
[10576] Failed to execute script wordcount
Moreover, I'm pretty sure this is just the beginning. Is there any other solution?
Any help will be appreciated. I know these issues were discussed before, and I apologize in advance, but non of the solutions I found work for me.
PS: the list of "missing modules" in warn.txt is long as the Great Wall of China, is it normal? Especially considering that only two modules are in use.
Well, I solved the issue, but the solution is not very elegant:
pyinstaller --add-data "./wordcount.kv;." --hiddenimport pkg_resources.py2_warn --hiddenimport win32timezone --hiddenimport textract.parsers.pptx_parser --hiddenimport textract.parsers.docx_parser wordcount.py
Then I copied libpng16-16.dll from one of the Python folders to the /dist/ folder.
If somebody knows better way please share it...
I've been going through this package of python scripts:
https://github.com/werdeil/clementine-last-export
To convert from pyqt4 to pyqt5 as pyqt4 is no longer supported on my OS.
I did both a manual conversion and a conversion using the following script:
https://github.com/rferrazz/pyqt4topyqt5
Both the script and the conversion from pyqt4->pyqt5 seem straight-forward but once I am done converting the scripts I still get:
Traceback (most recent call last):
File "gui.py", line 374, in <module>
main()
File "gui.py", line 355, in main
cleg = ClemLastExportGui()
File "gui.py", line 45, in __init__
self.load_config()
File "gui.py", line 350, in load_config
self.config = pickle.load(open(self.configfile))
File "/usr/lib64/python2.7/pickle.py", line 1384, in load
return Unpickler(file).load()
File "/usr/lib64/python2.7/pickle.py", line 864, in load
dispatch[key](self)
File "/usr/lib64/python2.7/pickle.py", line 1139, in load_reduce
value = func(*args)
ImportError: No module named PyQt4.QtCore
despite the fact that no refrences to pyqt4 are even active in the source:
~/projects/clementine-last-export $ grep -i pyqt4 -r *
README.txt:pyqt4 stopped being supported by most Linux Operating Systems
I looked through the libraries on my system and pyqt4 is entirely gone, so that doesn't seem likely to be the cause.
Could someone take a look at my code here:
https://github.com/davidsmind/clementine-last-export
Or point me in the right direction if it is a system issue?
I'm trying to use behave to run selenium tests but I'm stuck at start of that idea.
I've setup python, selenium and behave as it should be. I'm running python scripts with selenium without an problem. My problems starts when I try to run them with behave. My python is 3.5.2, selenium is 2.53.2 and behave is 1.2.5.
When I try to run any feature file I get errors bellow. It doesn't matter if I try to run it with PyCharm IDE or directly from command prompt. Does any one have a clue what is wrong or what I do wrong?
Errors:
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pycharm\behave_runner.py", line 269, in <module>
_BehaveRunner(my_config, base_dir).run()
File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pycharm\_bdd_utils.py", line 92, in run
number_of_tests = self._get_number_of_tests()
File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pycharm\_bdd_utils.py", line 206, in _get_number_of_tests
for feature in self._get_features_to_run():
File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pycharm\behave_runner.py", line 209, in _get_features_to_run
self.__real_runner.run()
File "C:\Python35\lib\site-packages\behave-1.2.5-py3.5.egg\behave\runner.py", line 672, in run
File "C:\Python35\lib\site-packages\behave-1.2.5-py3.5.egg\behave\runner.py", line 677, in run_with_paths
File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pycharm\behave_runner.py", line 92, in load_hooks
super(_RunnerWrapper, self).load_hooks(filename)
File "C:\Python35\lib\site-packages\behave-1.2.5-py3.5.egg\behave\runner.py", line 631, in load_hooks
File "C:\Python35\lib\site-packages\behave-1.2.5-py3.5.egg\behave\runner.py", line 303, in exec_file
File "features\environment.py", line 11
print("Before scenario\n")
^
IndentationError: unindent does not match any outer indentation level
Process finished with exit code 1
Your traceback returns: 'IndentationError: unindent does not match any outer indentation level'.
This is usually an indicator that your tab/spaces of your indentation level is incorrect.
Could you try to reformat the file tabbing to 4 spaces?
As khelwood noted, the file you should take a look at is 'features\environment.py' around line number 11.
This usually should solve this problem.
i am trying to adding a new module in my database.
i faced this problem that i can not any solution.
the code of my init.py is:
from trytond.pool import Pool
from grh.Employe import *
def register():
Pool.register(
Employe,
module='grh', type_='model')
and the problem after trying is :
File "/usr/local/bin/trytond", line 5, in <module>
pkg_resources.run_script('trytond==3.2.2', 'trytond')
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 528, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1394, in run_script
execfile(script_filename, namespace, namespace)
File "/usr/local/lib/python2.7/dist-packages/trytond-3.2.2-py2.7.egg/EGG-INFO/scripts/trytond", line 113, in <module>
trytond.server.TrytonServer(options).run()
File "/usr/local/lib/python2.7/dist-packages/trytond-3.2.2-py2.7.egg/trytond/server.py", line 123, in run
Pool(db_name).init(update=update, lang=lang)
File "/usr/local/lib/python2.7/dist-packages/trytond-3.2.2-py2.7.egg/trytond/pool.py", line 151, in init
lang=lang)
File "/usr/local/lib/python2.7/dist-packages/trytond-3.2.2-py2.7.egg/trytond/modules/__init__.py", line 428, in load_modules
_load_modules()
File "/usr/local/lib/python2.7/dist-packages/trytond-3.2.2-py2.7.egg/trytond/modules/__init__.py", line 393, in _load_modules
graph = create_graph(module_list)[0]
File "/usr/local/lib/python2.7/dist-packages/trytond-3.2.2-py2.7.egg/trytond/modules/__init__.py", line 159, in create_graph
raise Exception('Module %s not found' % module)
help me please
Your are running the server from /usr/local/lib/python2.7/dist-packages/trytond-3.2.2-py2.7.egg, so the module must be in /usr/local/lib/python2.7/dist-packages/trytond-3.2.2-py2.7.egg/trytond/modules/ folder or installed in /usr/local/lib/python2.7/dist-packages/
For development proposes I will recommend you running from sources without installing the packages. If you have done this, you're not connecting to the right tryton instance.
If you want to always install your module, just run python setup.py install (assuming that your custom module have the setup.py file defined with the correct methods and name).
You can find a template of setup.py on http://hg.tryton.org/tryton-tools/file/b1bf3e9fe771/contrib-module-setup.tmpl
Traceback (most recent call last):
File "<string>", line 1, in <module>
File py_installer/PyInstaller-2.1/PyInstaller/loader/pyi_importers.py", line 270, in load_module
File py_installer/PyInstaller-2.1/FaceMatcher/build/FaceMatcher/out00-PYZ.pyz/proj_code", line 11, in <module>
File PyInstaller-2.1/PyInstaller/loader/pyi_importers.py", line 270, in load_module
File PyInstaller-2.1/FaceMatcher/build/FaceMatcher/out00-PYZ.pyz/skimage.transform", line 1, in <module>
File py_installer/PyInstaller-2.1/PyInstaller/loader/pyi_importers.py", line 270, in load_module
File py_installer/PyInstaller-2.1/FaceMatcher/build/FaceMatcher/out00-PYZ.pyz/skimage.transform.hough_transform", line 7, in <module>
File py_installer/PyInstaller-2.1/PyInstaller/loader/pyi_importers.py", line 409, in load_module
File "_hough_transform.pyx", line 13, in init skimage.transform._hough_transform (skimage/transform/_hough_transform.c:7337)
File "py_installer/PyInstaller-2.1/PyInstaller/loader/pyi_importers.py", line 270, in load_module
File "py_installer/PyInstaller-2.1/FaceMatcher/build/FaceMatcher/out00-PYZ.pyz/skimage.draw", line 1, in <module>
File "py_installer/PyInstaller-2.1/PyInstaller/loader/pyi_importers.py", line 409, in load_module
File "_draw.pyx", line 1, in init skimage.draw._draw (skimage/draw/_draw.c:7257)
ImportError: No module named geometry
I have been getting above error. Could some one please tell me how would i fix it?
The problem is skimage.transform requires on a small 'chain' of hidden imports. These are imports that happen in a variety of ways Pyinstaller cannot detect automatically, namely using __import__, etc. So, you must tell Pyinstaller directly about these imports so it knows to inspect them and add them to your build.
You can do this in two ways:
The --hidden-import command-line flag, which is useful if you have only a few modules to specify.
'hook' files, which can help you group a few hidden imports based on what module requires them.
For example, for your specific situation you can create a file called hook-skimage.transform.py and put the following in it:
hiddenimports = ['skimage.draw.draw',
'skimage.draw._draw',
'skimage.draw.draw3d',
'skimage._shared.geometry',
'skimage._shared.interpolation',
'skimage.filter.rank.core_cy']
You may not need all of those modules specified. Your build was only lacking skimage._shared.geometry so you could try only including that file with the --hidden-import command-line flag, or only including skimage._shared.geometry in your hook-skimage.transform.py file. However, those specific hidden imports fixed my scenario on Windows 7 64-bit with skimage 0.9.3.
Then, tell pyinstaller where to look for your extra hook files. So, if you put the hook-skimage.transform.py file in your '.' directory you need to modify your pyinstaller build command to include --additional-hooks-dir=.
This will cause pyinstaller to inspect the modules you specified when it tries to import skimage.transform.hough_line as your output mentioned.