Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 为Python3和PyQt构建可执行文件_Python 3.x_Pyqt4_Py2exe_Pyinstaller - Fatal编程技术网

Python 3.x 为Python3和PyQt构建可执行文件

Python 3.x 为Python3和PyQt构建可执行文件,python-3.x,pyqt4,py2exe,pyinstaller,Python 3.x,Pyqt4,Py2exe,Pyinstaller,我使用PyQt4在Python3.1中构建了一个相当简单的应用程序。完成后,我希望将应用程序分发到计算机,而不安装任何一个 我几乎完全关心Windows平台,所以我的目标是拥有一个可执行文件,最后可能还有一些资源文件和.dll 经过四处搜寻,我得出结论 py2exe仅支持2.7版之前的Python pyinstaller仅支持2.6版之前的Python cx\u Freeze对我不起作用,因为我在尝试执行成功生成的二进制文件时不断出现以下错误: Y:\Users\lulz\build\ex

我使用PyQt4在Python3.1中构建了一个相当简单的应用程序。完成后,我希望将应用程序分发到计算机,而不安装任何一个

我几乎完全关心Windows平台,所以我的目标是拥有一个可执行文件,最后可能还有一些资源文件和.dll

经过四处搜寻,我得出结论

  • py2exe仅支持2.7版之前的Python
  • pyinstaller仅支持2.6版之前的Python
  • cx\u Freeze对我不起作用,因为我在尝试执行成功生成的二进制文件时不断出现以下错误:

Y:\Users\lulz\build\exe.win32-3.1>system\u shutdown.exe
回溯(最近一次呼叫最后一次):
文件“Y:\Program Files(x86)\Python\lib\site packages\cx\u Freeze\initscripts\Console3.py”,第27行,在exec(代码,m.。\uuuuu dict\uuu)中
文件“Y:/Users/lulz/Documents/Coding/Python3/projects/System Shutdown/System_Shutdown.pyw”,第5行,从PyQt4导入QtCore
文件“ExtensionLoader_PyQt4_QtCore.py”,第16行,在AttributeError中:“NoneType”对象没有属性“modules”
所以我的问题基本上是两个问题:

  • 除了cx\U冻结之外,还有其他方法可以用我的配置构建二进制文件吗
  • 如果不是,cx_冻结问题可能是什么
  • 如有必要,我可以提供关于第二个问题的更多信息,如调用cx\U Freeze、distutils设置脚本等


    已经感谢您的帮助和评论。

    您可以通过在cx\u freeze包中的freeze.py中添加一行代码来解决此问题

    这里描述的是:

    这至少对我有用:)

    干杯,
    Almar对于Python 3.3及更高版本,这里有一个很好的解决方案:

    安装py2exe:

    pip install py2exe
    
    然后除了“your_script.py”文件之外,添加以下“Make_exe.py”文件:

    from distutils.core import setup
    import py2exe, sys
    
    class Make_exe():
        def __init__(self, python_script):
            sys.argv.append('py2exe')
    
            setup(
                console=[{'script': python_script}],
                zipfile = None,
                options={
                    'py2exe': 
                    {
                        'bundle_files': 1, 
                        'compressed': True,
                        # Add includes if necessary, e.g. 
                        'includes': ['lxml.etree', 'lxml._elementpath', 'gzip'],
                    }
                }
            )
    
    if __name__ == '__main__':
        Make_exe('your_script.py')
    
    如果每次在python中运行“your_script.py”时都希望将其自身重建为“your_script.exe”,则可以在其主脚本中添加:

    import subprocess
    import sys
    
    if __name__ == '__main__':
        currentFile = sys.argv[0]
        if currentFile.lower().endswith(".py"):
            exitCode = subprocess.call("python Make_exe.py")
            if exitCode==0 :
                dirName = os.path.dirname(currentFile)
                exeName = os.path.splitext(os.path.basename(currentFile))[0] + '.exe'
                exePath = dirName + "/dist/" + exeName
                cmd = [exePath] + sys.argv[1:]
                print ("Executing command:\n %s" % cmd)
                exitCode = subprocess.call(cmd)
            sys.exit(exitCode)
        else:
            print ("This will be executed only within the new generated EXE File...")
    

    好问题。py2exe在过去对于我们的目的来说非常好。py2exe现在可以用于Python3了!我会尝试这一点,一旦我得到它,并张贴我的结果。谢谢你!这最终奏效了,必须添加您提到的代码行并包括sip。现在还有一个问题,当启动我的nice GUI应用程序时,如何抑制控制台窗口。虽然有点晚,但对于未来的读者,您可以通过使用Win32 GUI库冻结来抑制控制台窗口。我通过pip安装了cx_freeze 4.3.3。我正在使用python 3.4。我应该在哪里尝试添加这行代码?我找不到任何冻结。不过脚本中有一个cxfreeze.py。
    import subprocess
    import sys
    
    if __name__ == '__main__':
        currentFile = sys.argv[0]
        if currentFile.lower().endswith(".py"):
            exitCode = subprocess.call("python Make_exe.py")
            if exitCode==0 :
                dirName = os.path.dirname(currentFile)
                exeName = os.path.splitext(os.path.basename(currentFile))[0] + '.exe'
                exePath = dirName + "/dist/" + exeName
                cmd = [exePath] + sys.argv[1:]
                print ("Executing command:\n %s" % cmd)
                exitCode = subprocess.call(cmd)
            sys.exit(exitCode)
        else:
            print ("This will be executed only within the new generated EXE File...")