簡體   English   中英

PyInstaller:“ImportError:沒有名為 os 的模塊”

[英]PyInstaller: “ImportError: No module named os”

我正在嘗試學習 PyInstaller。 我創建了兩個簡單的文件,Test.py:

import os

和測試規范:

anal = Analysis (["Test.py"])
pyz = PYZ(anal.pure)
exe = EXE(anal.scripts, pyz, name="Test.exe", exclude_binaries=1, debug=1)
coll = COLLECT(exe, anal.binaries, name="dist")

然后我跑了:

Build.py Test.spec

這運行時沒有任何錯誤消息,並生成了一個包含多個文件的目錄 dist,包括 Test.exe。 當我運行 Test.exe 時,它以 output 失敗:

Found embedded PKG: C:\Documents and Settings\Rade\My Documents\Development\Test\Test.exe
Extracting binaries
manifestpath: C:\Documents and Settings\Rade\My Documents\Development\Test\Test.
exe.manifest
Error activating the context
python27.dll
Manipulating evironment
PYTHONPATH=C:/Documents and Settings/Rade/My Documents/Development/Test
importing modules from CArchive
extracted iu
extracted struct
extracted archive
Installing import hooks
outPYZ1.pyz
Running scripts
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named os
RC: -1 from Test
OK.

我確定我犯了一些愚蠢的初學者錯誤,但是什么?

對於像這樣的簡單文件,您應該使用Makespec.py來創建規范,而不是手動編寫。 對於大型項目,您可以使用 Makespec.py 的 output 作為模板並對其進行編輯。

http://www.pyinstaller.org/export/latest/tags/1.4/doc/Manual.html#create-a-spec-file-for-your-project

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM