2014-02-10 5 views
0

my_python_file.py이라는 제목의 파이썬 파일을 가지고 있는데, 특히 python-docx 모듈을 사용하는 .doc 파일이 있습니다. .doc은 완벽하게 생성되며 아무런 문제가 없습니다. 문제는 내 스크립트의 .exe을 빌드하고 .doc을 만들려고 할 때 발생합니다. AssertionError 문제가 나타납니다..exe가 생성 될 때 AsserionError를 제공하는 Python의 docx 모듈

이 내 EXE 메이커 코드 (exe_maker.py)입니다 :

from distutils.core import setup 
import py2exe, sys, os 
sys.argv.append('py2exe') 

setup(
    options = {'py2exe': {'bundle_files': 3, 'compressed': True, 'includes': ['lxml.etree', 'lxml._elementpath', 'gzip', 'docx']}}, 
    windows = [{'script': "my_python_file.py"}], 
    zipfile = None, 
) 

다른 위치로 파이썬 스크립트를 이동하면 오류가 발생합니다 것으로 보인다. 그것이 .exe 파일이 아닙니다 때 작동으로

savedox
document = newdocument() 
[...] 
coreprops = coreproperties(title=title, subject=subject, creator=creator, keywords=keywords) 
approps = appproperties() 
contenttypes2 = contenttypes() 
websettings2 = websettings() 
wordrelationships2 = wordrelationships(relationships) 
path_save = "C:\output" 
savedocx(document, coreprops, approps, contenttypes2, websettings2, wordrelationships2, path_save) 

잘 writen된다

File "docx.pyc", line 1063, in savedocx 
AssertionError 

이것은 savedocx 라인입니다.

docx 모듈을 올바르게 작동 시키려면 어떻게해야합니까? exe를 만들 때 다른 경로/변수를 더 추가해야합니까? 사전

+1

AssertionError를 발생시키는 행은 무엇입니까? 또한 코드는 GitHub에 있거나 어딘가에서 검사 할 수 있습니까? 여기에 가야 할 것이별로 없습니다. 또한 post-Word 2007 파일에는 이전 .doc 확장자가 아닌'.docx' 확장자가 주어집니다. 또한 PIL 또는 Pillow가 종속성 목록에없는 것을 확인합니다. – scanny

+0

'savedoc'의 줄을 추가했지만 질문에서'.exe'가 빌드되지 않을 때 완벽하게 작동하므로'savedoc' 줄의 프로그래밍 문제가 아닙니다. 미리 감사드립니다. –

+0

필자는''ncludes'' 행에'PIL'을 추가했으나 작동하지 않습니다. –

답변

0

에서

덕분에 나는 시스템의 파이썬 폴더에있는 DOCX 계란 폴더의 api.py 파일을 edditing하여 문제를 해결했다.

이 변경 :

_thisdir = os.path.split(__file__)[0] 
_default_docx_path = os.path.join(_thisdir, 'templates', 'default.docx') 

이받는 사람 :

thisdir = os.getcwd() 
_default_docx_path = os.path.join(thisdir, 'templates', 'default.docx') 

첫 번째는 실제 실행중인 프로그램을 복용하고 templates 폴더를 찾을 경로에 추가되었다.
C:\myfiles\myprogram.exe\templates\default.docx

해결 방법은 실행중인 프로그램이 아니라 경로 만 사용합니다.
C:\myfiles\templates\default.docx

0

대신 일부 라이브러리 파일을 변경, 나는 즉, 쉽게와 청소기 파이썬 - DOCX 명시 적으로 어디에 템플릿을 찾아 말할 찾을 :

document = Document('whatever/path/you/choose/to/some.docx') 

이 효과적으로 py2exe에와 DOCX 경로를 해결 문제.