加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – PyInstaller新手:你好世界

发布时间:2020-12-20 13:44:32 所属栏目:Python 来源:网络整理
导读:我正在尝试使用PyInstaller v2.1从简单的hello world脚本( Python 2.7)创建单个可执行文件.脚本hello.py只有一行: print 'Hello,World!' 然后我在包含脚本的文件夹中打开一个命令窗口,然后输入: pyinstaller -F hello.py 我得到以下输出: C:Userschris
我正在尝试使用PyInstaller v2.1从简单的hello world脚本( Python 2.7)创建单个可执行文件.脚本hello.py只有一行:

print 'Hello,World!'

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

pyinstaller -F hello.py

我得到以下输出:

C:UserschrisworkspaceHelloPy>pyinstaller -F hello.py
43 INFO: wrote C:UserschrisworkspaceHelloPyhello.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:UserschrisworkspaceHelloPy
1332 INFO: checking Analysis
1539 INFO: checking PYZ
1644 INFO: checking PKG
1655 INFO: building because C:UserschrisworkspaceHelloPybuildhellohello.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:UserschrisworkspaceHelloPydisthello.exe

build和dist文件夹按预期创建,可执行文件也是如此.我尝试运行它并获得以下输出:

C:UserschrisworkspaceHelloPy>cd dist

C:UserschrisworkspaceHelloPydist>hello
WARNING: file already exists but should not:      C:UserschrisAppDataLocalTemp_MEI58962includepyconfig.h
Hello,World!

如果我在没有单个可执行开关的情况下运行pyinstaller,即没有-F,那么我没有得到“警告:文件已经存在”

我可能错过了一些非常明显的东西,但我已经四处寻找,似乎无法在其他任何地方找到这个问题.任何帮助或指向其他解决方案的指针将非常感激.

解决方法

向PyInstaller团队 here报告了一张票,指出这个SO答案作为解决方法:
Pyinstaller –onefile warning pyconfig.h when importing scipy or scipy.signal

您可以使用a = Analysis行下的以下块修改spec文件:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读