PyInstaller 新手:你好世界 [英] PyInstaller newbie: hello world

查看:53
本文介绍了PyInstaller 新手:你好世界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PyInstaller v2.1 从简单的 hello world 脚本 (Python 2.7) 创建单个可执行文件.脚本 hello.py 只有一行:

I'm trying to use PyInstaller v2.1 to create a single executable out of a simple hello world script (Python 2.7). The script, hello.py, has just one line:

print 'Hello, World!'

然后我在包含脚本的文件夹中打开一个命令窗口并输入:

I then open a command window in the folder containing the script and enter:

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 文件夹按预期创建,可执行文件也是如此.我尝试运行它并获得以下输出:

The build and dist folder are created as expected, as is the executable. I try to run it and get the following output:

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,那么我不会收到警告:文件已经存在"

If I run pyinstaller instead without the single executable switch, i.e. without the -F then I don't get the "WARNING: file already exists"

我可能遗漏了一些非常明显的东西,但我四处搜索,似乎在其他任何地方都找不到这个问题.任何帮助或指向其他地方解决方案的指针将不胜感激.

I'm probably missing something really obvious but I've searched around and can't seem to find this problem anywhere else. Any help or a pointer to the solution elsewhere would be much appreciated.

推荐答案

有一张票报告给 PyInstaller 团队 此处 指向此 SO 答案作为解决方法:导入 scipy 或 scipy.signal 时 Pyinstaller --onefile 警告 pyconfig.h

There was a ticket reported to the PyInstaller team here that points to this SO answer as a workaround: Pyinstaller --onefile warning pyconfig.h when importing scipy or scipy.signal

您在 a=Analysis 行下使用以下块修改规范文件:

You modify your spec file with the following block under the a=Analysis line:

for d in a.datas:
    if 'pyconfig' in d[0]: 
        a.datas.remove(d)
        break

这应该对你有用,因为它似乎对大多数人都有效.

That should work for you as it seems to work for most.

我个人更喜欢 py2exe.这是Hello, World"示例的链接,该示例与您尝试实现的完全相同:http://www.py2exe.org/index.cgi/Tutorial

Personally I prefer py2exe. Here is a link to a "Hello, World" example do to the exact same thing you are trying to achieve: http://www.py2exe.org/index.cgi/Tutorial

这篇关于PyInstaller 新手:你好世界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆