使用Python 3.5/3.6将.py转换为.exe文件?

问题描述:

我使用PyQt5构建的GUI在Python 3.6中创建了一个应用程序。某些模块仅适用于Python 3.5和3.6。 我设法使用py2app将它打包在Mac上。我正试图在Windows上做同样的事情。我试图使用this guide,但我仍然有问题。 对于我明白,我有3种选择: 使用Python 3.5/3.6将.py转换为.exe文件?

  • cx_Freeze
  • 1)py2exe

    根据here py2exe仍不可用于python3

    1. py2exe
    2. pyinstaller .6,我需要使用python3.5。

      使用3.5,我得到这个错误,编译停止:

      error: [Errno 2] No such file or directory: 'C:\\Users\\carlo\\AppData\\Roaming\\Python\\Python35\\site-packages\\py2exe\\run-py3.5-win32.exe' 
      

      2)pyinstaller 通过Python3.5运行pyinstaller为: pyinstaller --onefile APP.py

      我得到的只是一堆警告(lib找不到),但编译到最后。创建的EXE,不过,打开命令提示符窗口,弹出如下错误:

      Traceback (most recent call last): 
          File "site-packages\PyInstaller\loader\rthooks\pyi_rth_qt5plugins.py", line 46, in <module> 
          File "c:\program files (x86)\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 573, in load_module 
          module = loader.load_module(fullname) 
      ImportError: DLL load failed: %1 is not a valid Win32 application. 
      Failed to execute script pyi_rth_qt5plugins 
      

      3)cx_Freeze 使用python3.5,它首先带来的 'TCL_LIBRARY' 的错误。按照说明here编译顺利进行。然而,创建的应用程序会立即打开并关闭。它根本不起作用。 使用python3.6,编译看起来没问题。当我尝试打开应用程序时,弹出此错误。我只是设法采取快速screen-shot:

      有没有人有任何建议?我不考虑任何替代方案?

    我设法解决了这个问题! 我按照说明here。 我第一次跑了(用Python3.5):

    pyinstaller CodeName.py

    然后我修改的.spec文件在link指示,奇迹发生了!