I'm in Windows, using pyInstaller to package an python file. But something error occurred:
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "D:\Useful Apps\pyinstaller-2.0\PyInstaller\loader\iu.py", line 386, in i
mportHook
mod = _self_doimport(nm, ctx, fqname)
File "D:\Useful Apps\pyinstaller-2.0\PyInstaller\loader\iu.py", line 480, in d
oimport
exec co in mod.__dict__
File "D:\Useful Apps\pyinstaller-2.0\server\build\pyi.win32\server\out00-PYZ.p
yz\SocketServer", line 132, in <module>
File "D:\Useful Apps\pyinstaller-2.0\PyInstaller\loader\iu.py", line 386, in i
mportHook
mod = _self_doimport(nm, ctx, fqname)
File "D:\Useful Apps\pyinstaller-2.0\PyInstaller\loader\iu.py", line 480, in d
oimport
exec co in mod.__dict__
File "D:\Useful Apps\pyinstaller-2.0\server\build\pyi.win32\server\out00-PYZ.p
yz\socket", line 47, in <module>
File "D:\Useful Apps\pyinstaller-2.0\PyInstaller\loader\iu.py", line 409, in i
mportHook
raise ImportError("No module named %s" % fqname)
ImportError: No module named _socket
I know that _socket
is in path C:\Python27\libs\_socket.lib
, but how can let the EXE
find that file?
This sounds like a job for hidden imports (only available in the latest builds).
From the docs
Had similar issues. Here's my fix for PyQt5, cffi, python 3.4.3:
This fixes the 'sip' not found error and the '_cffi_backend' one if that comes up:
Look at 'pathex' and 'hiddenimports' above. Those are the only changes from default generated. Build exe with:
pyinstaller LightShowApp.spec -F
I ran that outside of venv or pip-win - whateverTF that crap is for!
You can add the path to your application spec file.
In the Analysis object you can specify
pathex=['C:\Python27\libs\', 'C:\Python27\Lib\site-packages']
, and any other path ...Note that if the path is not found there is no problem ... I have paths from linux as well in there.
None of the above answers worked for me, but I did get it to work. I was using openpyxl and it required jdcal in the datetime.py module. None of the hidden imports or any of those methods helped, running the exe would still say jdcal not found. The work-around that I used was to just copy the few functions from jdcal directly into the datetime.py in the openpyxl code. Then ran
pyinstaller -F program.py
and it worked!
If you are using virtualenv you should use the "-p" or "--path='D:...'" option. Like this:
What this does is generates foo.spec file with this pathex path