我正在尝试使用 PyInstaller v2.1 从简单的 hello world 脚本(Python 2.7)创建单个可执行文件。脚本 hello.py 只有一行:
print 'Hello, World!'
然后,我在包含脚本的文件夹中打开一个命令窗口并输入:
pyinstaller -F hello.py
我得到以下输出:
C:\Users\chris\workspace\HelloPy>pyinstaller -F hello.py
43 INFO: wrote C:\Users\chris\workspace\HelloPy\hello.spec
66 INFO: Testing for ability to set icons, version resources...
79 INFO: ... resource update available
83 INFO: UPX is not available.
115 INFO: Processing hook hook-os
299 INFO: Processing hook hook-time
304 INFO: Processing hook hook-cPickle
402 INFO: Processing hook hook-_sre
585 INFO: Processing hook hook-cStringIO
721 INFO: Processing hook hook-encodings
741 INFO: Processing hook hook-codecs
1332 INFO: Extending PYTHONPATH with C:\Users\chris\workspace\HelloPy
1332 INFO: checking Analysis
1539 INFO: checking PYZ
1644 INFO: checking PKG
1655 INFO: building because C:\Users\chris\workspace\HelloPy\build\hello\hello.exe.manifest changed
1656 INFO: building PKG (CArchive) out00-PKG.pkg
7801 INFO: checking EXE
7803 INFO: rebuilding out00-EXE.toc because pkg is more recent
7803 INFO: building EXE from out00-EXE.toc
7809 INFO: Appending archive to EXE C:\Users\chris\workspace\HelloPy\dist\hello.exe
build 和 dist 文件夹以及可执行文件均按预期创建。我尝试运行它并得到以下输出:
C:\Users\chris\workspace\HelloPy>cd dist
C:\Users\chris\workspace\HelloPy\dist>hello
WARNING: file already exists but should not: C:\Users\chris\AppData\Local\Temp\_MEI58962\include\pyconfig.h
Hello, World!
如果我在没有单个可执行开关的情况下运行 pyinstaller,即没有 -F,那么我不会收到“警告:文件已存在”
我可能错过了一些非常明显的东西,但我已经四处搜索,似乎在其他地方找不到这个问题。任何帮助或指向其他地方的解决方案的指针将不胜感激。
有一张票报告给了 PyInstaller 团队here http://www.pyinstaller.org/ticket/783指出这个 SO 答案作为解决方法:导入 scipy 或 scipy.signal 时 Pyinstaller --onefile 警告 pyconfig.h https://stackoverflow.com/a/19163950/3927911
您可以使用以下块修改您的规范文件a=Analysis
line:
for d in a.datas:
if 'pyconfig' in d[0]:
a.datas.remove(d)
break
这应该对你有用,因为它似乎对大多数人都有效。
我个人更喜欢py2exe。以下是“Hello, World”示例的链接,它与您想要实现的目标完全相同:http://www.py2exe.org/index.cgi/Tutorial http://www.py2exe.org/index.cgi/Tutorial
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)