2016-10-12 1 views
1

파이썬 프로젝트에 .exe를 생성하려고합니다. 생성 된 .exe 파일을 열면 오류가 발생합니다. 포함 된 모듈 wordcloud이 보통 소스 코드 옆에있는 파일을 열려고 시도하기 때문입니다.cx_freeze가 필요로하는 모듈에 비 파이썬 파일을 포함 시키시겠습니까?

모듈 자체는 다음과 같습니다 (C:/python/Lib/site-packages/wordcloud에 있음). (C:/.../my-application/builds/0.1/my-app/my-app.exe/wordcloud에서 발견) 생성 된 나 cx_Freeze exe 인 내부

__init__.py 
__pycache__/ 
color_from_image.py 
DroidSansMono.ttf 
query_integral_image.pyd 
stopwords 
wordcloud.py 
wordcloud_cli.py 

모듈은 다음과 같습니다

color_from_image.pyc 
query_integral_image.pyc 
wordcloud.pyc 
__init__.pyc 

는 당신이 그것을 알고하지 않은 경우 나 cx_Freeze은 .EXE 자체의 세대 내부의 모든 모듈이 포함되어 있습니다 erated .exe는 실행 파일이자 아카이브입니다.

이 generatec exe/archive에서 원본 소스 내에있는 stopwords 파일을 추가하고 싶습니다. 이것이 가능한가?

이 질문과 cx_freeze의 include_files 옵션의 가장 큰 차이점은 파일이 결과 폴더에 있지 않아야하지만 결과 .exe 파일의 wordcloud 종속성 바로 옆에 있어야한다는 점입니다.

편집 : 경로로 .exe와 함께 include_files을 사용하려고했지만 예상대로 작동하지 않습니다.

error: build\exe.win32-3.3\my-app.exe: Cannot create a file when that file already exists

답변

0

이것은 include_zip 옵션을 사용하여 가능하다.

setup.py에서

:

import sys 
from cx_Freeze import setup, Executable 

# GUI applications require a different base on Windows (the default is for a 
# console application). 
base = None 
if sys.platform == "win32": 
    base = "Win32GUI" 

zip_includes = [ 
    (r'C:\Python33\Lib\site-packages\wordcloud\stopwords', 'wordcloud/stopwords'), 
    (r'C:\Python33\Lib\site-packages\wordcloud\DroidSansMono.ttf', 'wordcloud/DroidSansMono.ttf') 
] 

setup( name = "my-app", 
     version = "0.1", 
     description = "my-app description", 
     options = {"build_exe": {"zip_includes": zip_includes}}, 
     executables = [Executable("entry.py", base=base)]) 

이 여전히 파일을 읽을 수 open('.../archived-file.exe/wordcloud/stopwords')을 사용하고 필요한 모듈 때문에,이 문제를 해결 끝나지 않았다, open 보관에서 읽기를 지원하지 않습니다 너무 나쁜 파일.

+0

zip 파일의 경우 유용 할 수 있습니다. https://docs.python.org/3/library/zipfile.html – shuttle87

+0

@ shuttle87 'open'을 호출하는 코드가 내 것이 아니므로 내 자신과의 종속성, 또는 빌드하는 동안 패치 : – Azeirah

관련 문제