Python脚本打包为exe文件
(7)如果没有指定--include-path,或者没有在某个.py文件中写上import _elementpath as DONTUSE,都会出现如下找不到_elementpath模块的错误: D:\Projects\Google\pyblogpost\2exe\dist>BlogPost.exeTraceback (most recent call last):
File "D:\Projects\Google\pyblogpost\2exe\BlogPost.py", line 11, in <module>
import BlogConfig
File "BlogConfig.py", line 5, in <module>
File "ExtensionLoader_lxml_etree.py", line 12, in <module>
File "lxml.etree.pyx", line 39, in init lxml.etree (src/lxml/lxml.etree.c:1399
44)
ImportError: No module named _elementpath
(8)不能有中文,即使是注释中也不能有,否则出现如下错误。
codeString = fp.read()
File "C:\Python31\lib\codecs.py", line 300, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 557-558: invalid
data
尝试把编码由cp936改为utf-8,也不可以,把文件中ASCII另存为UTF-8,也不行,有如下错误:
File "BlogConfig.py", line 1
\ufeff#!/usr/bin/python
^
SyntaxError: invalid character in> 4、补充说明另外一种打包方式。
第3点讲的是通过命令行指定参数打包,也可以采用如下方式:
(1)新建setup.py文件,内容大致如下:(我使用的是上述第3点讲述的方法,没有修改参数)
(2)在命令行执行:python setup.py build
这种打包方法,在cxfreeze工具的sample中也大量使用。
页:
[1]