Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
583 views
in Technique[技术] by (71.8m points)

python - Imported module not found in PyInstaller

I'm working in Windows, using PyInstaller to package a python file. But some error is occuring:

Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "D:Useful Appspyinstaller-2.0PyInstallerloaderiu.py", line 386, in importHook
    mod = _self_doimport(nm, ctx, fqname)
  File "D:Useful Appspyinstaller-2.0PyInstallerloaderiu.py", line 480, in doimport
    exec co in mod.__dict__
  File "D:Useful Appspyinstaller-2.0serveruildpyi.win32serverout00-PYZ.pyzSocketServer", line 132, in <module>
  File "D:Useful Appspyinstaller-2.0PyInstallerloaderiu.py", line 386, in importHook
    mod = _self_doimport(nm, ctx, fqname)
  File "D:Useful Appspyinstaller-2.0PyInstallerloaderiu.py", line 480, in doimport
    exec co in mod.__dict__
  File "D:Useful Appspyinstaller-2.0serveruildpyi.win32serverout00-PYZ.pyzsocket", line 47, in <module>
  File "D:Useful Appspyinstaller-2.0PyInstallerloaderiu.py", line 409, in importHook
    raise ImportError("No module named %s" % fqname)
ImportError: No module named _socket

I know that _socket is in path C:Python27libs\_socket.lib, but how can let the generated EXE find that file?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

pyinstaller.exe --onefile --paths=D:envLibsite-packages  .foo.py

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...