繁体   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