PyInstaller:“ImportError:没有名为os的模块”

时间:2011-06-10 17:39:58

标签: python pyinstaller

我正在尝试学习PyInstaller。我创建了两个简单的文件,Test.py:

import os

和Test.spec:

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时,它输出失败:

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.

我确定我犯了一些愚蠢的初学者的错误,但是什么?

1 个答案:

答案 0 :(得分:2)

对于像这样的简单文件,您应该使用Makespec.py来创建规范而不是手动编写。对于大型项目,您可以使用Makespec.py的输出作为模板并进行编辑。

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