【问题标题】:PyInstaller not working on simple HelloWorld ProgramPyInstaller 不适用于简单的 HelloWorld 程序
【发布时间】:2013-10-14 01:03:01
【问题描述】:

所以我在 64 位 Windows 7 上运行,并且我使用 Pip 和 PyWin32 设置了 Pyinstaller。我有 python 2.7。

我用这段代码做了一个简单的hello world程序

print "hello world!"

我将文件放在与 PyInstaller 相同的目录下,并在命令提示符下运行此代码

pyinstaller.py helloWorld.py

然而,当我尝试这样做时,我收到以下错误消息:

Error loading Python DLL: C:\PROGRA~1\PYINST~1.1\build\HELLOW~1\python27.dll (error code 126)

我做错了什么,我该如何解决?

【问题讨论】:

    标签: python-2.7 pyinstaller


    【解决方案1】:

    使用 -F 标志运行以生成独立的 exe:

    pyinstaller -F helloworld.py
    

    会输出到 dist/helloworld.exe

    注意这与不使用 -F 时的位置不同,请确保之后运行正确的 exe。

    【讨论】:

    • 值得注意的是,它现在似乎输出到dist/{filename},而不是build/{filename}
    • 谢谢,我已更新答案以反映新位置
    【解决方案2】:

    感谢@tul!我的 pyinstaller 版本将它放到 dist\helloworld.exe!

    如果你从 C:\Python27\Scripts... 开始,那也是 C:\Python27\Scripts\dist...

    但无论你有它,我建议在你的 .py 旁边放置一个批处理文件,以便随时单击即可重新编译:

    我设置了它,所以在 .py 位置除了 .exe 之外什么都没有,临时的东西进入临时目录:

    @echo off
    :: get name from filename without path and ext
    set name=%~n0
    echo ========= %name% =========
    
    :: cut away the suffix "_build"
    set name=%name:~0,-6%
    set pypath=C:\Python27\Scripts
    set buildpath=%temp%
    
    if not exist %name%.py (
        echo ERROR: "%name%.py" does not exist here!
        pause
        exit /b
    )
    
    %pypath%\pyinstaller.exe --onefile -y %~dp0%name%.py --distpath=%~dp0 --workpath=%buildpath% --specpath=%buildpath%
    

    我将它命名为 .py 文件加上“_build”并再次删除批处理脚本中的后缀。 瞧。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多