7

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.

2 Answers2

14

i had a same issue earlier.. resolves this problem by importing sqlalchemy.sql.default_comparator on my main program..

user3801578
  • 141
  • 1
  • 5
  • 1
    That worked. I think one could also prevent this error by defining a hidden import for sqlalchemy. – JohnGalt Aug 19 '17 at 14:29
  • how does one define a hidden import? – hasdrubal Nov 02 '17 at 08:53
  • 1
    @user1111652 You can add the module name as a string to the hidden param of the Analysis initializer, which is included in your pyinstaller spec file. Note spec files are perfectly valid Python code, don't fear breaking anything. – fredpi Mar 20 '18 at 12:27
1

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

Jonathan Biemond
  • 359
  • 3
  • 12