Imported module not found in PyInstaller

I work on Windows, I use PyInstallerPython to package the file. But there is some kind of error:

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 importHook
    mod = _self_doimport(nm, ctx, fqname)
  File "D:\Useful Apps\pyinstaller-2.0\PyInstaller\loader\iu.py", line 480, in doimport
    exec co in mod.__dict__
  File "D:\Useful Apps\pyinstaller-2.0\server\build\pyi.win32\server\out00-PYZ.pyz\SocketServer", line 132, in <module>
  File "D:\Useful Apps\pyinstaller-2.0\PyInstaller\loader\iu.py", line 386, in importHook
    mod = _self_doimport(nm, ctx, fqname)
  File "D:\Useful Apps\pyinstaller-2.0\PyInstaller\loader\iu.py", line 480, in doimport
    exec co in mod.__dict__
  File "D:\Useful Apps\pyinstaller-2.0\server\build\pyi.win32\server\out00-PYZ.pyz\socket", line 47, in <module>
  File "D:\Useful Apps\pyinstaller-2.0\PyInstaller\loader\iu.py", line 409, in importHook
    raise ImportError("No module named %s" % fqname)
ImportError: No module named _socket

I know what _socketis in the way C:\Python27\libs\_socket.lib, but how to let the generated EXEfind this file?

+6
source share
5 answers

You can add the path to your spec application file.

In the Analysis object, you can specify pathex=['C:\Python27\libs\', 'C:\Python27\Lib\site-packages']any other path ...

Please note that if the path is not found, there is no problem ... I also have linux paths.

+2
source

This seems to work for hidden imports (only available in recent builds).

a = Analysis(['myscript.py'], 
             hiddenimports = ['_socket'], 
             <and everything else>)
+2

virtualenv, "-p" "--path =" D:... "". :

pyinstaller.exe --onefile --paths=D:\env\Lib\site-packages  .\foo.py

, , foo.spec pathex

+2

, . openpyxl, jdcal datetime.py. - , exe , jdcal . , , , jdcal datetime.py openpyxl. pyinstaller -F program.py

!

0

There were similar problems. Here is my fix for PyQt5, cffi, python 3.4.3:

This fixes the error "sip" not found and "_cffi_backend" if this happens:

# -*- mode: python -*-

block_cipher = None


a = Analysis(['LightShowApp.py'],
             pathex=['c:\\MyProjects\\light-show-editor-36',
             'c:\\Python34\\libs\\', 'c:\\Python34\\Lib\\site-packages'],
             binaries=None,
             datas=None,
             hiddenimports=['sip', 'cffi'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='LightShowApp',
          debug=False,
          strip=False,
          upx=True,
          console=True )

Look at "pathex" and "hiddenimports" above. These are the only changes generated by default. Create an exe with:

pyinstaller LightShowApp.spec -F

I ran this outside of venv or pip-win - anyTF in which shit!

0
source

All Articles