Pregunta

I am using pyinstaller on a python script that imports matplotlib.pyplot. The exe created by pyinstaller runs just fine when a directory full of files is generated. However, the exe fails when the pyinstaller -F option is used to create a single exe file. There are two problems reported when it fails:

  1. WARNING: file already exists but should not: C:\Users\Vern\AppData\Local\Temp_MEI33442\Include\pyconfig.h

  2. The last two lines of traceback report this:

File "C:\Users\Vern\Documents\Python\testplot\build\testplot\out00-PYZ.pyz\matplotlib.pyplot", line 80, in _backend_selection

File "C:\PyInstaller\PyInstaller\loader\pyi_importers.py", line 409, in load_module module = imp.load_module(fullname, fp, filename, self._c_ext_tuple)

ImportError: could not import module 'PySide.QtCore'

This last one, the ImportError is where the exe stops.

I am using python 2.7.6 and pyinstaller 2.1 on a Windows 7 machine.

There are some warning messages generated when pyinstaller runs. They look like these:

WARNING: lib not found: QtGui4.dll dependency of C:/WinPython/python-2.7.6/Lib/sitepackages/PyQt4/plugins\iconengines\qsvgicon4.dll

WARNING: lib not found: QtSvg4.dll dependency of C:/WinPython/python-2.7.6/Lib/sitepackages/PyQt4/plugins\iconengines\qsvgicon4.dll

WARNING: lib not found: QtCore4.dll dependency of C:/WinPython/python-2.7.6/Lib/sitepackages/PyQt4/plugins\iconengines\qsvgicon4.dll

...more like those followed but have been omitted.

These warnings are generated by pyinstaller when the -F option is either used or not used so I do not know if they are relevant but they seem very suspicious. I am out of my area of expertise on much of this so please excuse my ignorance. At any rate, the exe runs just fine even with these warnings when not using the -F option. It only fails when using the -F option.

I have searched around on SO and goggle but without any luck. I would like to be able to use the -F option to generate a single exe file for distribution. I am not using any other options for pyinstaller and I have not done anything to the spec file that gets automatically generated. My other python scripts that do not import matplotlib work fine when converted to a single exe file using -F.

¿Fue útil?

Solución

Using PyInstaller I was also getting ImportError: could not import module 'PySide.QtCore' when trying to package my program using --onefile, but there were no issues when using the --onedir option. This was despite the fact that PySide.QtCore was appearing in the temp directory at runtime as expected. In my code I was importing PyQt4 directly while PySide was being imported by other modules. From what you posted it looks like both modules are also being used in your code.

After reading this I tried adding 'PySide' as an exclude in my spec file to force exclusive use of PyQt4 and the exe now runs fine. Excluding either PySide or PyQt4 might help in your case too.

Otros consejos

This question was answered here: Pyinstaller QtCore Module import error

In summary, PyInstaller 2.1 has a bug with QT but it is fixed in the development version. So get that or wait for PyInstaller 2.2.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top