cx_Freeze是一个打包python为exe的好库,可是安装后打包一些程序后不能运行
解决参考http://comments.gmane.org/gmane.comp.python.cx-freeze.user/1856
参考:http://stackoverflow.com/questions/23920073/cx-freeze-error-python-34
打开的时候出现:
python\lib\site-packages\cx_Freeze\freezer.py:574: UserWarning: Duplicate name: 'importlib/__init__.pyc' outFile.writestr(zinfo, data)
然后打开cmd,在命令行中运行exe文件
错误如下:
Traceback (most recent call last): File "C:\Python34\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27, in <module> exec(code, m.__dict__) File "forecast.py", line 4, in <module> File "C:\Python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2214, in _find_and_load File "C:\Python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2189, in _find_and_load_unlocked File "C:\Python\32-bit\3.4\lib\importlib\_bootstrap.py", line 321, in _call_with_frames_removed File "C:\Python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2214, in _find_and_load File "C:\Python\32-bit\3.4\lib\importlib\_bootstrap.py", line 2203, in _find_and_load_unlocked File "C:\Python\32-bit\3.4\lib\importlib\_bootstrap.py", line 1191, in _load_unlocked File "C:\Python\32-bit\3.4\lib\importlib\_bootstrap.py", line 1161, in _load_backward_compatible AttributeError: 'module' object has no attribute '_fix_up_module'
原因是有bug,歪果仁说版本Bug,正在试图解决,实际上已经解决了。
看我的:
查看自己的python位数:
>>> import sys, platform >>> platform.architecture() ('64bit', 'WindowsPE')
然后从万能仓库http://www.lfd.uci.edu/~gohlke/pythonlibs/#cx_freeze
下载对应版本:
当然,先要卸载我之前安装的msi,如下:
下载之后的库是zip结尾的,改成whl结尾
然后打开cmd,转到该文件目录,使用:
然后转到python安装目录下的cx-Freeze实例去试试成不成功,如图:
命令是:
python setup.py build
最后运行一下:
完全没问题,因为只是缺少wx包,我没装。
而最简单的setup.py文件可以在这里找,如图:
# -*- coding: utf-8 -*- # A very simple setup script to create a single executable # # hello.py is a very simple 'Hello, world' type script which also displays the # environment in which the script runs # # Run the build process by running the command 'python setup.py build' # # If everything works well you should find a subdirectory in the build # subdirectory that contains the files needed to run the script without Python from cx_Freeze import setup, Executable executables = [ Executable('hello.py') ] setup(name='hello', version='0.1', description='Sample cx_Freeze script', executables=executables )
此时已经结束了,好愉快。
其实,我还有很多东西需要写成博文,没动力,啊呀。
可以在我的百度云上下载:一只尼玛
我Build了一下,发现了,我是要用python画图的:
No module named 'matplotlib.backends.backend_tkagg'
看来解决了一个问题,还要再解决一个。
参考:http://stackoverflow.com/questions/20582384/importerror-no-module-named-backend-tkagg
I've seen this before, also on openSUSE (12.3). The fix is to edit the default matplotlibrc file. Here's how you find where the default matplotlibrc file lives, and where it lives on my machine: >>> import matplotlib >>> matplotlib.matplotlib_fname() '/usr/lib64/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc' The backend setting is the first configuration option in this file. Change it from TkAgg to Agg, or to some other backend you have installed on your system. The comments in the matplotlibrc file list all backends supported by matplotlib. The backend specified in this file is only the default; you can still change it at runtime by adding the following two lines, before any other matplotlib import: import matplotlib matplotlib.use("Agg") # or whichever backend you wish to use
意思就是说你可以把site-packages/matplotlib/mpl-data/matplotlibrc里面的第一个配置的TkAgg改为Agg,或者在程序的最开始加入以下:
import matplotlib matplotlib.use("Agg") # or whichever backend you wish to use
改了之后可以打包了,可是没有图出来,卧槽,明明有这些文件,难道没有安装Tk包
ValueError: Unrecognized backend string "gdkagg": valid strings are ['gdk', 'GTK', 'TkAgg', 'svg', 'Qt4Agg', 'ps', 'emf', 'pdf', 'template', 'agg', 'GTK3Agg', 'cairo', 'pgf', 'GTKAgg', 'nbAgg', 'CocoaAgg', 'WXAgg', 'WX', 'GTKCairo', 'GTK3Cairo', 'WebAgg', 'Qt5Agg', 'MacOSX']
matplotlib.use("gdk")
一个个试着看!!!