0

我正在尝试学习 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 时,输出失败:

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.

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

4

1 回答 1

2

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

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

于 2011-06-10T18:25:47.003 回答