문제

PYQT4를 사용하여 Python 3.1에서 다소 간단한 응용 프로그램을 구축했습니다. 완료되기 위해, 나는 애플리케이션을 설치하지 않고 컴퓨터에 배포하기를 원합니다.

나는 거의 독점적으로 Windows 플랫폼에 관심이 있으므로 내 목표는 단일 실행 파일과 일부 리소스 파일과 .dlls를 갖는 것입니다.

주위를 찾아서 나는 결론에 도달했다.

  • py2exe 버전 2.7까지 Python 만 지원합니다
  • Pyinstaller 버전 2.6까지 Python 만 지원합니다
  • CX_Freeze 성공적으로 빌드 바이너리를 실행하려고 할 때 다음 오류를 계속 받기 때문에 나에게 효과가 없습니다.

Y:\Users\lulz\build\exe.win32-3.1>system_shutdown.exe
Traceback (most recent call last):
File "Y:\Program Files (x86)\Python\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 27, in exec(code, m.__dict__)
File "Y:/Users/lulz/Documents/Coding/Python3/projects/System Shutdown/system_shutdown.pyw", line 5, in from PyQt4 import QtCore
File "ExtensionLoader_PyQt4_QtCore.py", line 16, in AttributeError: 'NoneType' object has no attribute 'modules'

따라서 내 문제는 기본적으로 두 가지 문제입니다.

  1. CX_Freeze 이외의 다른 방법이 있습니까?
  2. 그렇지 않다면 CX_Freeze 문제는 무엇일까요?

CX_Freeze의 호출, Distutils Setup Script 등 필요한 경우 두 번째 문제에 대한 자세한 정보를 제공 할 수 있습니다.

당신의 도움과 의견에 대해 이미 감사합니다.

도움이 되었습니까?

해결책

CX_Freeze 패키지에서 Freeze.py를 위해 한 줄의 코드를 추가하여이 문제를 해결할 수 있습니다.

여기에 설명되어 있습니다.http://www.mail-archive.com/cx-freeze-users@lists.sourceforge.net/msg00212.html

그것은 적어도 나를 위해 일했다 :)

건배, 알마르

다른 팁

Python 3.3 이후에는 여기에는 좋은 해상도가 있습니다.py2exe- 단일 실행 파일을 생성합니다

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')

그리고 '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...")
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top