Imported module not found in PyInstaller

If you are using virtualenv you should use the "-p" or "--path='D:...'" option. Like this:

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

What this does is generates foo.spec file with this pathex path


This sounds like a job for hidden imports (only available in the latest builds).

From the docs

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

In my case, I had to delete all folders and files related to pyinstaller in my directory, i.e. __pycache__, build, dist, and *.spec. I re-ran the build and the exe worked.


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.