今天准备把写好的Python程序打包,结果折腾了一天。先是想用pyinstaller,发现打包出来运行不了,应该是它在处理import时出了问题。于是考虑用cx freeze代替,结果在安装的时候就报错了,后来找到了解决办法。
先是从http://sourceforge.net/projects/cx-freeze/files/上下载cx_Freeze(版本4.3.3)的包
解压,执行:sudo python setup.py install
出现的错误如下:
adding base module named StringIO
adding base module named UserDict
adding base module named _abcoll
adding base module named _weakrefset
adding base module named abc
adding base module named base64
adding base module named codecs
adding base module named copy
adding base module named copy_reg
adding base module named encodings
adding base module named encodings.aliases
adding base module named encodings.ascii
adding base module named encodings.base64_codec
adding base module named encodings.big5
adding base module named encodings.big5hkscs
adding base module named encodings.bz2_codec
adding base module named encodings.charmap
adding base module named encodings.cp037
adding base module named encodings.cp1006
adding base module named encodings.cp1026
adding base module named encodings.cp1140
adding base module named encodings.cp1250
adding base module named encodings.cp1251
adding base module named encodings.cp1252
adding base module named encodings.cp1253
adding base module named encodings.cp1254
adding base module named encodings.cp1255
adding base module named encodings.cp1256
adding base module named encodings.cp1257
adding base module named encodings.cp1258
adding base module named encodings.cp424
adding base module named encodings.cp437
adding base module named encodings.cp500
adding base module named encodings.cp720
adding base module named encodings.cp737
adding base module named encodings.cp775
adding base module named encodings.cp850
adding base module named encodings.cp852
adding base module named encodings.cp855
adding base module named encodings.cp856
adding base module named encodings.cp857
adding base module named encodings.cp858
adding base module named encodings.cp860
adding base module named encodings.cp861
adding base module named encodings.cp862
adding base module named encodings.cp863
adding base module named encodings.cp864
adding base module named encodings.cp865
adding base module named encodings.cp866
adding base module named encodings.cp869
adding base module named encodings.cp874
adding base module named encodings.cp875
adding base module named encodings.cp932
adding base module named encodings.cp949
adding base module named encodings.cp950
adding base module named encodings.euc_jis_2004
adding base module named encodings.euc_jisx0213
adding base module named encodings.euc_jp
adding base module named encodings.euc_kr
adding base module named encodings.gb18030
adding base module named encodings.gb2312
adding base module named encodings.gbk
adding base module named encodings.hex_codec
adding base module named encodings.hp_roman8
adding base module named encodings.hz
adding base module named encodings.idna
adding base module named encodings.iso2022_jp
adding base module named encodings.iso2022_jp_1
adding base module named encodings.iso2022_jp_2
adding base module named encodings.iso2022_jp_2004
adding base module named encodings.iso2022_jp_3
adding base module named encodings.iso2022_jp_ext
adding base module named encodings.iso2022_kr
adding base module named encodings.iso8859_1
adding base module named encodings.iso8859_10
adding base module named encodings.iso8859_11
adding base module named encodings.iso8859_13
adding base module named encodings.iso8859_14
adding base module named encodings.iso8859_15
adding base module named encodings.iso8859_16
adding base module named encodings.iso8859_2
adding base module named encodings.iso8859_3
adding base module named encodings.iso8859_4
adding base module named encodings.iso8859_5
adding base module named encodings.iso8859_6
adding base module named encodings.iso8859_7
adding base module named encodings.iso8859_8
adding base module named encodings.iso8859_9
adding base module named encodings.johab
adding base module named encodings.koi8_r
adding base module named encodings.koi8_u
adding base module named encodings.latin_1
adding base module named encodings.mac_arabic
adding base module named encodings.mac_centeuro
adding base module named encodings.mac_croatian
adding base module named encodings.mac_cyrillic
adding base module named encodings.mac_farsi
adding base module named encodings.mac_greek
adding base module named encodings.mac_iceland
adding base module named encodings.mac_latin2
adding base module named encodings.mac_roman
adding base module named encodings.mac_romanian
adding base module named encodings.mac_turkish
adding base module named encodings.mbcs
adding base module named encodings.palmos
adding base module named encodings.ptcp154
adding base module named encodings.punycode
adding base module named encodings.quopri_codec
adding base module named encodings.raw_unicode_escape
adding base module named encodings.rot_13
adding base module named encodings.shift_jis
adding base module named encodings.shift_jis_2004
adding base module named encodings.shift_jisx0213
adding base module named encodings.string_escape
adding base module named encodings.tis_620
adding base module named encodings.undefined
adding base module named encodings.unicode_escape
adding base module named encodings.unicode_internal
adding base module named encodings.utf_16
adding base module named encodings.utf_16_be
adding base module named encodings.utf_16_le
adding base module named encodings.utf_32
adding base module named encodings.utf_32_be
adding base module named encodings.utf_32_le
adding base module named encodings.utf_7
adding base module named encodings.utf_8
adding base module named encodings.utf_8_sig
adding base module named encodings.uu_codec
adding base module named encodings.zlib_codec
adding base module named genericpath
adding base module named linecache
adding base module named os
adding base module named posixpath
adding base module named quopri
adding base module named repr
adding base module named stat
adding base module named stringprep
adding base module named struct
adding base module named traceback
adding base module named types
adding base module named warnings
adding base module named weakref
running install
running bdist_egg
running egg_info
creating cx_Freeze.egg-info
writing cx_Freeze.egg-info/PKG-INFO
writing top-level names to cx_Freeze.egg-info/top_level.txt
writing dependency_links to cx_Freeze.egg-info/dependency_links.txt
writing cx_Freeze.egg-info/PKG-INFO
writing top-level names to cx_Freeze.egg-info/top_level.txt
writing dependency_links to cx_Freeze.egg-info/dependency_links.txt
writing manifest file ‘cx_Freeze.egg-info/SOURCES.txt’
reading manifest file ‘cx_Freeze.egg-info/SOURCES.txt’
reading manifest template ‘MANIFEST.in’
writing manifest file ‘cx_Freeze.egg-info/SOURCES.txt’
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
running build_ext
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Ibuild/temp.linux-x86_64-2.7 -I/usr/include/python2.7 -c source/bases/Console.c -o build/temp.linux-x86_64-2.7/source/bases/Console.o
x86_64-linux-gnu-gcc -pthread build/temp.linux-x86_64-2.7/source/bases/Console.o -o build/lib.linux-x86_64-2.7/cx_Freeze/bases/Console -s
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘GetImporterHelper’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:211:对‘PyObject_CallMethod’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:215:对‘PyErr_Clear’未定义的引用
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘GetDirName’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:66:对‘PyString_FromStringAndSize’未定义的引用
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘FatalError’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘SetExecutableName’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:93:对‘PyString_FromString’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:115:对‘PyString_FromStringAndSize’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:136:对‘PyString_FromString’未定义的引用
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘FatalError’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘SetExecutableName’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:155:对‘PyString_FromString’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:167:对‘PyString_FromString’未定义的引用
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘FatalError’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘SetExecutableName’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:102:对‘PyExc_OSError’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:102:对‘PyErr_SetFromErrnoWithFilename’未定义的引用
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘FatalError’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘main’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:64:对‘Py_NoSiteFlag’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:65:对‘Py_FrozenFlag’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:66:对‘Py_IgnoreEnvironmentFlag’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:67:对‘PyImport_FrozenModules’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:93:对‘Py_SetPythonHome’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:95:对‘Py_SetProgramName’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:96:对‘Py_GetProgramFullPath’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:97:对‘Py_Initialize’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:98:对‘PySys_SetArgv’未定义的引用
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘SetPathToSearch’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:186:对‘PySys_GetObject’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:189:对‘PyList_Insert’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:191:对‘PyList_Insert’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:193:对‘PyList_Insert’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:195:对‘PyList_Insert’未定义的引用
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘GetImporter’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:231:对‘PyImport_ImportModule’未定义的引用
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘ExecuteScript’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:295:对‘PyDict_New’未定义的引用
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘PopulateInitScriptDict’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:256:对‘PyEval_GetBuiltins’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:256:对‘PyDict_SetItemString’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:258:对‘PyDict_SetItemString’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:260:对‘PyDict_SetItemString’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:262:对‘PyDict_SetItemString’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:265:对‘PyDict_SetItemString’未定义的引用
build/temp.linux-x86_64-2.7/source/bases/Console.o:/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:268: more undefined references to `PyDict_SetItemString’ follow
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘ExecuteScript’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:303:对‘PyObject_CallMethod’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Common.c:307:对‘PyEval_EvalCode’未定义的引用
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘FatalError’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘main’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:105:对‘Py_Finalize’未定义的引用
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘FatalError’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:24:对‘PyErr_Print’未定义的引用
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:25:对‘Py_FatalError’未定义的引用
build/temp.linux-x86_64-2.7/source/bases/Console.o:在函数‘FatalScriptError’中:
/home/bill/Downloads/cx_Freeze-4.3.3/source/bases/Console.c:36:对‘PyErr_Print’未定义的引用
collect2: error: ld returned 1 exit status
error: command ‘x86_64-linux-gnu-gcc’ failed with exit status 1
然后在其bitbucket上发现了如下issue:https://bitbucket.org/anthony_tuininga/cx_freeze/issues/32/cant-compile-cx_freeze-in-ubuntu-1304
解决方法
把安装文件setup.py里的
if not vars.get("Py_ENABLE_SHARED", 0):
改成
if True:
修改后可以成功安装,成功解决问题。
版权声明:本文为博主原创文章,未经博主允许不得转载。