The issue:
So, after compilation, inside the dist folder, there is "PyQt5.Qt.pyd" file,
but I am getting this error:
Traceback (most recent call last):
File "main.py", line 102, in <module>
File "<frozen zipimport>", line 259, in load_module
File "<loader>", line 10, in <module>
File "<loader>", line 8, in __load
ImportError: (DLL load failed while importing QtWidgets: The specified module could not be found.) 'Z:\\Project\\dist\\PyQt5.QtWidgets.pyd'
I am pretty sure that that this "Qt" folder from "C:\Program Files (x86)\Python38-32\Lib\site-packages\PyQt5\Qt", which after compilation is converted to "PyQt5.Qt.pyd" file I guess, is responsible for this error. Because when I add this location to my Windows PATH: "C:\Program Files (x86)\Python38-32\Lib\site-packages\PyQt5\Qt\bin", the compiled program works flawlessly.
My temporary fix is:
I copied the "Qt" folder to the "dist", and made a batch script that adds ".\dist\Qt\bin" to PATH, for the current CMD window...Just so I can send it to my client to test it out for now...But this is far from the final solution... What to do?
(I have also tried to copy just "bin", or "platform\qwindows.dll" from "Qt" to dist, but no luck...)
I would appreciate any help or advice regarding this. Thanks in advance!
My info:
OS info:
Windows 10 x64, Python 3.8.6 x32
pip freeze:
altgraph==0.17
cachetools==4.1.1
fbs==0.9.0
future==0.18.2
macholib==1.14
pefile==2019.4.18
Pillow==8.0.1
py2exe==0.10.0.2
PyInstaller==3.4
PyQt5==5.15.1
PyQt5-sip==12.8.1
pywin32==228
pywin32-ctypes==0.2.0
six==1.15.0
py2exe setup.py:
from distutils.core import setup
import py2exe
setup(windows=[{"script":"main.py"}], options={"py2exe":{"includes":["PyQt5.Qt","PyQt5.sip","PyQt5.QtWidgets","PyQt5.QtCore", "PyQt5.QtGui"]}})
Copy all dll's from PyQt5\Qt\bin to dist, except the ones beginning with Qt5* (You might not need d3dcompiler_47, libEGL, libGLESv2 and opengl32sw if your not using direct3d or opengl)
I suggest you try out to run your application converted with py2exe on a newly installed windows (maybe in a virtual machine) to find out if it has other dependencies.
Update: Actually, I only needed to install Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019, without copying any dll files. https://support.microsoft.com/en-us/topic/the-latest-supported-visual-c-downloads-2647da03-1eea-4433-9aff-95f26a218cc0
Related
I am trying to install GDCM on Windows (10, x64) so I can use the GDCM package with Python 3.6.5, and am finding it completely impossible.
I have tried every combination of:
Installing GDCM-2.8.7-Windows-x86_64, GDCM-2.8.7-Windows-x86.exe, GDCM-2.8.4-Windows-x86.exe (separately, of course)
Adding To PYTHONPATH: C:\Program Files\Python36; C:\Program Files\Python36\Lib; C:\Program Files\Python36\DLLs; C:\Program Files\Python36\Scripts; C:\Program Files\GDCM 2.8; C:\Program Files\GDCM 2.8\lib; C:\Program Files\GDCM 2.8\bin; C:\Program Files\GDCM 2.8\include; C:\Program Files\GDCM 2.8\ (and even PYTHONHOME)
Copying the files gdcm.py, gdcmswig.py and _gdcmswig.pyd into site-packages and DLLs
The best I can get is copying the above mentioned files to site-packages, which allows python to detect the gdcm package (when the files are removed from site-packages it detects nothing), but returns the error:
>>> import gdcm
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files\Python36\lib\site-packages\gdcm.py", line 68, in
<module>
from gdcmswig import *
File "C:\Program Files\Python36\lib\site-packages\gdcmswig.py", line 20, in
<module>
_gdcmswig = swig_import_helper()
File "C:\Program Files\Python36\lib\site-packages\gdcmswig.py", line 19, in
swig_import_helper
return importlib.import_module(mname)
File "C:\Program Files\Python36\lib\importlib\__init__.py", line 126, in
import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed: The specified module could not be found.
Installing the _x86 version instead returns the error "%1 is not a Valid Win32 application".
I downloaded dependencyWalker to analyse _gdcmswig.pyd, but from this I cannot understand much. The problem is not MSVCP100.dll, as I have vc_redist_x64 installed. It does mention Python34.dll, but the answer below got the exact same installer working on Python 3.6.
The solution mentioned at:
how to install gdcm python wrapping on Windows System? does not work for me.
Lastly, I cannot get python to detect the package from the Program Files/GDCM 2.8/bin, regardless of what is in PATH, PYTHONPATH, or PYTHONHOME; I don't know if this is normal or not.
I have spent hours on this, to no avail; any help is greatly appreciated.
For posterity:
For me, it seems the issue was indeed that the official provided binaries were compiled for Python 3.4; I have no idea how this person got the same installer working on Python 3.6.
The solution was to build the package binaries myself; there was no "one-click" solution. For my ridiculously convoluted adventure in troubleshooting this problem, see: https://motivatedbylaziness.wordpress.com/2018/07/06/the-impossible-journey-of-a-simple-task/
I recently had this issue, and I solved it using:
python -m pip install python-gdcm
It seems that today (2022) there is a "one-click" solution
I am trying to wrap a Python script into an exe using PyInstaller (development version) for windows.
The script uses Pandas and I have been running into an error when running the exe.
Traceback (most recent call last): File "site-packages\pandas\__init__.py", line 26, in <module> File "C:\Users\Eddie\Anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__) File "site-packages\pandas\_libs\__init__.py", line 4, in <module> File "C:\Users\Eddie\Anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 714, in load_module
module = loader.load_module(fullname) File "pandas/_libs/tslib.pyx", line 1, in init pandas._libs.tslib ModuleNotFoundError: No module named 'pandas._libs.tslibs.timedeltas'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "G5k Version file Extract (with tkinter).py", line 15, in <module> File "C:\Users\Eddie\Anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__) File "site-packages\pandas\__init__.py", line 35, in <module> ImportError: C extension: No module named 'pandas._libs.tslibs.timedeltas' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
I have tried doing this for programs without pandas and everything was fine.
This is very similar to another question already solved for Python 2, but I am using Python 3 and that solution does not apply the same way due to the changed .spec file format.
Python 3.6
PyInstaller - version 3.3
Pandas - version 0.20.3
PyInstaller 3.3, Pandas 0.21.0, Python 3.6.1.
I was able to solve this thanks to not-yet published/committed fix to PyInstaller, see this and this. AND keeping the ability to pack it into one executable file.
Basically:
Locate PyInstaller folder..\hooks, e.g. C:\Program Files\Python\Lib\site-packages\PyInstaller\hooks.
Create file hook-pandas.py with contents (or anything similar based on your error):
hiddenimports = ['pandas._libs.tslibs.timedeltas']
Save it + I deleted .spec file, build and dist folders just to be sure.
Run pyinstaller -F my_app.py.
This fix should work as long as you don't upgrade or reinstall PyInstaller. So you don't need to edit .spec file.
Maybe they will include the fix sooner for us! :)
I'm not sure it may help you but following the solution on the post you mention work for me with python 3.6 pyinstaller 3.3 and pandas 0.21.0 on windows 7.
So adding this to the spec file just after analysis :
def get_pandas_path():
import pandas
pandas_path = pandas.__path__[0]
return pandas_path
dict_tree = Tree(get_pandas_path(), prefix='pandas', excludes=["*.pyc"])
a.datas += dict_tree
a.binaries = filter(lambda x: 'pandas' not in x[0], a.binaries)
Also my spec file format is the same as the one in the post you mention.
I managed to solve this problem by using the "--hidden-import" flag. Hopefully this can be helpful to someone else that comes across this thread.
pyinstaller --onefile --hidden-import pandas._libs.tslibs.timedeltas myScript.py
If you are using Anaconda, it is highly likely that when you were trying to uninstall some package it has disrupted pandas dependency and unable to get the required script. If you just run conda install pandas you might end up with another error:
module 'pandas' has no attribute 'compat'.
So, try uninstalling and reinstalling pandas conda uninstall pandas, Install it again using conda install pandas this will solve the problem.
On the other hand, if you are not using Anaconda., try doing the same on Command prompt pointing to Python scripts folder pip uninstall pandas & pip install pandas.
Most of the times, this should solve the problem. Just to be cover all the possibilities, don't forget to Launch Spyder from Anaconda after installing pandas.
I am trying to wrap a Python script into an exe using PyInstaller (development version) for windows.
The script uses Pandas and I have been running into an error when running the exe.
Traceback (most recent call last): File "site-packages\pandas\__init__.py", line 26, in <module> File "C:\Users\Eddie\Anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__) File "site-packages\pandas\_libs\__init__.py", line 4, in <module> File "C:\Users\Eddie\Anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 714, in load_module
module = loader.load_module(fullname) File "pandas/_libs/tslib.pyx", line 1, in init pandas._libs.tslib ModuleNotFoundError: No module named 'pandas._libs.tslibs.timedeltas'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "G5k Version file Extract (with tkinter).py", line 15, in <module> File "C:\Users\Eddie\Anaconda3\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__) File "site-packages\pandas\__init__.py", line 35, in <module> ImportError: C extension: No module named 'pandas._libs.tslibs.timedeltas' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
I have tried doing this for programs without pandas and everything was fine.
This is very similar to another question already solved for Python 2, but I am using Python 3 and that solution does not apply the same way due to the changed .spec file format.
Python 3.6
PyInstaller - version 3.3
Pandas - version 0.20.3
PyInstaller 3.3, Pandas 0.21.0, Python 3.6.1.
I was able to solve this thanks to not-yet published/committed fix to PyInstaller, see this and this. AND keeping the ability to pack it into one executable file.
Basically:
Locate PyInstaller folder..\hooks, e.g. C:\Program Files\Python\Lib\site-packages\PyInstaller\hooks.
Create file hook-pandas.py with contents (or anything similar based on your error):
hiddenimports = ['pandas._libs.tslibs.timedeltas']
Save it + I deleted .spec file, build and dist folders just to be sure.
Run pyinstaller -F my_app.py.
This fix should work as long as you don't upgrade or reinstall PyInstaller. So you don't need to edit .spec file.
Maybe they will include the fix sooner for us! :)
I'm not sure it may help you but following the solution on the post you mention work for me with python 3.6 pyinstaller 3.3 and pandas 0.21.0 on windows 7.
So adding this to the spec file just after analysis :
def get_pandas_path():
import pandas
pandas_path = pandas.__path__[0]
return pandas_path
dict_tree = Tree(get_pandas_path(), prefix='pandas', excludes=["*.pyc"])
a.datas += dict_tree
a.binaries = filter(lambda x: 'pandas' not in x[0], a.binaries)
Also my spec file format is the same as the one in the post you mention.
I managed to solve this problem by using the "--hidden-import" flag. Hopefully this can be helpful to someone else that comes across this thread.
pyinstaller --onefile --hidden-import pandas._libs.tslibs.timedeltas myScript.py
If you are using Anaconda, it is highly likely that when you were trying to uninstall some package it has disrupted pandas dependency and unable to get the required script. If you just run conda install pandas you might end up with another error:
module 'pandas' has no attribute 'compat'.
So, try uninstalling and reinstalling pandas conda uninstall pandas, Install it again using conda install pandas this will solve the problem.
On the other hand, if you are not using Anaconda., try doing the same on Command prompt pointing to Python scripts folder pip uninstall pandas & pip install pandas.
Most of the times, this should solve the problem. Just to be cover all the possibilities, don't forget to Launch Spyder from Anaconda after installing pandas.
I tried to run the following command, in the folder of my Django project:
$ python manage.py dbshell
It shows me this error:
$python manage.py dbshell
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "C:\Python25\lib\site-packages\django\core\management\__init__.py", line
362, in execute_manager
utility.execute()
File "C:\Python25\lib\site-packages\django\core\management\__init__.py", line
303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python25\lib\site-packages\django\core\management\base.py", line 195,
in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python25\lib\site-packages\django\core\management\base.py", line 222,
in execute
output = self.handle(*args, **options)
File "C:\Python25\lib\site-packages\django\core\management\base.py", line 351,
in handle
return self.handle_noargs(**options)
File "C:\Python25\lib\site-packages\django\core\management\commands\dbshell.py
", line 9, in handle_noargs
from django.db import connection
File "C:\Python25\lib\site-packages\django\db\__init__.py", line 41, in <modul
e>
backend = load_backend(settings.DATABASE_ENGINE)
File "C:\Python25\lib\site-packages\django\db\__init__.py", line 17, in load_b
ackend
return import_module('.base', 'django.db.backends.%s' % backend_name)
File "C:\Python25\Lib\site-packages\django\utils\importlib.py", line 35, in im
port_module
__import__(name)
File "C:\Python25\lib\site-packages\django\db\backends\mysql\base.py", line 13
, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No mo
dule named MySQLdb
First question is, why does Python not simply include this MySQLdb module?
OK, just fine, try to search to solve this message.
I have looked around stackoverflow.com for installing this module but did not have a good result.
Download this module at: http://sourceforge.net/projects/mysql-python/
Comes to the installation of this module on my Windows Vista system.
After the extraction of the package, I run the cmd prompt to continue with the installation:
$ python setup.py install
Again it showed me one other message:
D:\SOFTWARE\PROGRAMMING\MySQL-python-1.2.3c1>python setup.py install
Traceback (most recent call last):
File "setup.py", line 5, in <module>
from setuptools import setup, Extension
ImportError: No module named setuptools
Playing around with this error message, I know that there is the ez_setup.py within the package:
$python ez_setup.py
It seems that everything is OK:
D:\SOFTWARE\PROGRAMMING\MySQL-python-1.2.3c1>python ez_setup.py
Downloading http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c9-py
2.5.egg
Processing setuptools-0.6c9-py2.5.egg
Copying setuptools-0.6c9-py2.5.egg to c:\python25\lib\site-packages
Adding setuptools 0.6c9 to easy-install.pth file
Installing easy_install-script.py script to C:\Python25\Scripts
Installing easy_install.exe script to C:\Python25\Scripts
Installing easy_install-2.5-script.py script to C:\Python25\Scripts
Installing easy_install-2.5.exe script to C:\Python25\Scripts
Installed c:\python25\lib\site-packages\setuptools-0.6c9-py2.5.egg
Processing dependencies for setuptools==0.6c9
Finished processing dependencies for setuptools==0.6c9
Now comes back to the setup.py to install again:
$python setup.py install
It again gave me one other error message:
D:\SOFTWARE\PROGRAMMING\MySQL-python-1.2.3c1>python setup.py install
running install
running bdist_egg
....
copying MySQLdb\constants\CLIENT.py -> build\lib.win32-2.5\MySQLdb\constants
running build_ext
error: Python was built with Visual Studio 2003;
extensions must be built with a compiler than can generate compatible binaries.
Visual Studio 2003 was not found on this system. If you have Cygwin installed,
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.
How can I fix this problem?
Did you try looking here: http://sourceforge.net/projects/mysql-python/files/
That is the download area of MySQLdb project, it has nothing to do with django, so your question is incorrect - django does not make switching database backends hard, you just change one line. And of course, your python installation should support that database first, so by downloading binary package for Windows from the link I gave above (chose correct version to match your version of python) you can avoid all the hassle of compiling the source release.
Most probably you need either MySQL-python-1.2.2.win32-py2.5.exe or MySQL-python-1.2.2.win32-py2.4.exe
Uh, this isn't Django, this is you downloading some unspecified Python environment and expecting it to magically do everything exactly the way you wanted it to. Find a good tutorial on this and follow the instructions.
BTW, this is a very helpful forum, but giving no specifics and then delivering a non-question with an attitude is not a good way to get people to feel helpful.
I once had the same problem running Python and MySQL on the same computer. Like the guys/gals said above, Python does not come with built-in support for MySQL, so you will need to download the connectors.
The link given above by #kibitzer will most likely not work on Windows successfully, so go here to download a copy of the connector that works with windows. It comes with installer and no need to run setup.py script manually.
I tried to run the following command, in the folder of my Django project:
$ python manage.py dbshell
It shows me this error:
$python manage.py dbshell
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "C:\Python25\lib\site-packages\django\core\management\__init__.py", line
362, in execute_manager
utility.execute()
File "C:\Python25\lib\site-packages\django\core\management\__init__.py", line
303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python25\lib\site-packages\django\core\management\base.py", line 195,
in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python25\lib\site-packages\django\core\management\base.py", line 222,
in execute
output = self.handle(*args, **options)
File "C:\Python25\lib\site-packages\django\core\management\base.py", line 351,
in handle
return self.handle_noargs(**options)
File "C:\Python25\lib\site-packages\django\core\management\commands\dbshell.py
", line 9, in handle_noargs
from django.db import connection
File "C:\Python25\lib\site-packages\django\db\__init__.py", line 41, in <modul
e>
backend = load_backend(settings.DATABASE_ENGINE)
File "C:\Python25\lib\site-packages\django\db\__init__.py", line 17, in load_b
ackend
return import_module('.base', 'django.db.backends.%s' % backend_name)
File "C:\Python25\Lib\site-packages\django\utils\importlib.py", line 35, in im
port_module
__import__(name)
File "C:\Python25\lib\site-packages\django\db\backends\mysql\base.py", line 13
, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No mo
dule named MySQLdb
First question is, why does Python not simply include this MySQLdb module?
OK, just fine, try to search to solve this message.
I have looked around stackoverflow.com for installing this module but did not have a good result.
Download this module at: http://sourceforge.net/projects/mysql-python/
Comes to the installation of this module on my Windows Vista system.
After the extraction of the package, I run the cmd prompt to continue with the installation:
$ python setup.py install
Again it showed me one other message:
D:\SOFTWARE\PROGRAMMING\MySQL-python-1.2.3c1>python setup.py install
Traceback (most recent call last):
File "setup.py", line 5, in <module>
from setuptools import setup, Extension
ImportError: No module named setuptools
Playing around with this error message, I know that there is the ez_setup.py within the package:
$python ez_setup.py
It seems that everything is OK:
D:\SOFTWARE\PROGRAMMING\MySQL-python-1.2.3c1>python ez_setup.py
Downloading http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c9-py
2.5.egg
Processing setuptools-0.6c9-py2.5.egg
Copying setuptools-0.6c9-py2.5.egg to c:\python25\lib\site-packages
Adding setuptools 0.6c9 to easy-install.pth file
Installing easy_install-script.py script to C:\Python25\Scripts
Installing easy_install.exe script to C:\Python25\Scripts
Installing easy_install-2.5-script.py script to C:\Python25\Scripts
Installing easy_install-2.5.exe script to C:\Python25\Scripts
Installed c:\python25\lib\site-packages\setuptools-0.6c9-py2.5.egg
Processing dependencies for setuptools==0.6c9
Finished processing dependencies for setuptools==0.6c9
Now comes back to the setup.py to install again:
$python setup.py install
It again gave me one other error message:
D:\SOFTWARE\PROGRAMMING\MySQL-python-1.2.3c1>python setup.py install
running install
running bdist_egg
....
copying MySQLdb\constants\CLIENT.py -> build\lib.win32-2.5\MySQLdb\constants
running build_ext
error: Python was built with Visual Studio 2003;
extensions must be built with a compiler than can generate compatible binaries.
Visual Studio 2003 was not found on this system. If you have Cygwin installed,
you can try compiling with MingW32, by passing "-c mingw32" to setup.py.
How can I fix this problem?
Did you try looking here: http://sourceforge.net/projects/mysql-python/files/
That is the download area of MySQLdb project, it has nothing to do with django, so your question is incorrect - django does not make switching database backends hard, you just change one line. And of course, your python installation should support that database first, so by downloading binary package for Windows from the link I gave above (chose correct version to match your version of python) you can avoid all the hassle of compiling the source release.
Most probably you need either MySQL-python-1.2.2.win32-py2.5.exe or MySQL-python-1.2.2.win32-py2.4.exe
Uh, this isn't Django, this is you downloading some unspecified Python environment and expecting it to magically do everything exactly the way you wanted it to. Find a good tutorial on this and follow the instructions.
BTW, this is a very helpful forum, but giving no specifics and then delivering a non-question with an attitude is not a good way to get people to feel helpful.
I once had the same problem running Python and MySQL on the same computer. Like the guys/gals said above, Python does not come with built-in support for MySQL, so you will need to download the connectors.
The link given above by #kibitzer will most likely not work on Windows successfully, so go here to download a copy of the connector that works with windows. It comes with installer and no need to run setup.py script manually.