2017-11-30 1 views
-1

pyqt4를 사용하고 있습니다. 아이콘이 추가되었습니다.pyqt4 py2exe 아이콘 추가

basis = sys.argv[0] 
required_folder = os.path.split(basis)[0] 
# print required_folder 
imagepath = required_folder + '\mark.JPG' 
icon = QtGui.QIcon() 

icon.addPixmap(QtGui.QPixmap(_fromUtf8(imagepath)), QtGui.QIcon.Normal, QtGui.QIcon.Off) 
MainWindow.setWindowIcon(icon) 

py2exe의 setup.py에서 자원에 아이콘을 추가하려고합니다.

#setup.py 

from distutils.core import setup 
import py2exe 

setup(
    windows=[{"script": "MainFile.py"}], 
    options={ 
     "py2exe": 
     { 
      "dll_excludes" : ["MSVCP90.dll"], 
      "includes": ['encodings', 'encodings.*'] 
     } 
    } 
) 

python 스크립트로 프로그램을 시작할 때 내 아이콘이 보입니다. py2exe로 exe 프로그램을 만들면 프로그램이 제대로 작동하지만 아이콘이 사라집니다. enter image description here

========================== ===========================

나는 이미 그것을 해결했습니다. 그래서, 여기에 내 코드가있다. enter image description here

py2exe에 가져 오지 않습니다. 가져올 수없는 이유는 무엇입니까?

============================================== ================= 코드를 변경했습니다. 내가 cmd에 py2exe를 실행할 때. "예기치 않은 종료 오류" * 데이터 파일 복사 * < - 실행이 중지되었습니다.

setup(
windows=[{"script": "2017_12_01.py", "icon_resources": [(1, "mark.jpg")]}], 
data_files = [('imageformats', [r'C:\Python27\Lib\site-packages\PyQt4\plugins\imageformats\qjpeg4.dll'])], 
options={ 
    "py2exe": 
    { 
     "dll_excludes" : ["MSVCP90.dll"], 
     "includes": ['encodings', 'encodings.*', "sip"] 

    } 
}, 

)

는이 코드를 실행. enter image description here

+0

좋아, 난 정말 노력했다. Py2exe는 초보자에게 가장 쉽지 않으며 문제 발생 후 문제가 발생합니다. 시도해보십시오 : PyInstaller. 'py install pyinstaller' 그리고 나서'pyinstaller path/to/your/file.py -i path/to/your/icon.ico'을 실행하고 완료하십시오. – Pat

+0

또는, 만약 당신이 붙들고 싶다면 http://www.py2exe.org/index.cgi/Tutorial#Step52 – Pat

+0

슬프게도 pyinstaller가 작동하지 않습니다. py2exe에 대해 한 번 더 확인하십시오. 코드를 변경했습니다. – Layla

답변

0

이 리소스로 아이콘을 추가해야합니다. 그냥 확인 자사의 "질환자를"합니다

"icon_resources": [(1, "myicon.ico")] 

당신의 코드에서, 다음과 같이 구현해야합니다

#setup.py 

from distutils.core import setup 
import py2exe 

setup(
    windows = [ 
     { 
      "script": "MainFile.py", 
      "icon_resources": [(1, "myicon.ico")] 
     } 
    ], 
options={ 
     "py2exe": 
     { 
      "dll_excludes" : ["MSVCP90.dll"], 
      "includes": ['encodings', 'encodings.*'] 
     } 
     } 
) 

출처 : http://www.py2exe.org/index.cgi/CustomIcons

+0

이미지 파일 형식 .jpg를 .ico로 변경해야합니까? – Layla

+0

나는 mark.ico와 mark.jpg를 만들었습니다. 그런 다음 구현했습니다. 하지만 내가 더블 클릭 exe 파일. "런타임 오류! R6034"응용 프로그램이 C 런타임 라이브러리를 잘못로드하려고 시도했습니다. 자세한 내용은 응용 프로그램 지원 팀에 문의하십시오. " – Layla

+0

또한 PyInstaller를 추천합니다. 내가 던진 것에는 문제가 없었어. 그냥 껍질 (Windows 용 cmd)'pip install pyinstaller' 그리고 나서'pyinstaller path/to/your/file.py -i path/to/your/icon.ico'을 열고 완료하십시오. – Pat