回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我现在不知道如何通过py2exe打包:</p>
<p>我正在运行命令:</p>
<pre><code>python setup2.py py2exe
</code></pre>
<p>通过python 2.7.5和matplotlib 1.3.0以及py2exe 0.6.9和0.6.10dev</p>
<p>这适用于matplotlib 1.2.x</p>
<p>我已经阅读了<a href="http://www.py2exe.org/index.cgi/ExeWithEggs" rel="noreferrer">http://www.py2exe.org/index.cgi/ExeWithEggs</a>,并尝试实现处理mpl_工具包的建议,因为它已经成为一个名称空间包。</p>
<p>我也想在这里得到答案:<a href="http://matplotlib.1069221.n5.nabble.com/1-3-0-and-py2exe-regression-td41723.html" rel="noreferrer">http://matplotlib.1069221.n5.nabble.com/1-3-0-and-py2exe-regression-td41723.html</a></p>
<p>向mpl工具包中添加空的<code>__init__.py</code>可以使其工作,但这只是解决问题的一种方法。</p>
<p><strong>有人能建议我需要什么来让py2exe与matplotlib 1.3.0中的mpl_toolkits.axes_grid1一起工作吗?:</strong></p>
<hr/>
<p>测试mpl.py是:</p>
<pre><code>from mpl_toolkits.axes_grid1 import make_axes_locatable, axes_size
if __name__ == '__main__':
print make_axes_locatable, axes_size
</code></pre>
<hr/>
<p>setup2.py是:</p>
<pre><code>import py2exe
import distutils.sysconfig
from distutils.core import setup
# attempts to get it to work
import modulefinder
import matplotlib
import mpl_toolkits.axes_grid1
__import__('pkg_resources').declare_namespace("mpl_toolkits")
__import__('pkg_resources').declare_namespace("mpl_toolkits.axes_grid1")
modulefinder.AddPackagePath("mpl_toolkits", matplotlib.__path__[0])
modulefinder.AddPackagePath("mpl_toolkits.axes_grid1", mpl_toolkits.axes_grid1.__path__[0])
# end of attempts to get it to work
options={'py2exe': {'packages' : ['matplotlib', 'mpl_toolkits.axes_grid1', 'pylab', 'zmq'],
'includes': ['zmq', 'six'],
'excludes': ['_gdk', '_gtk', '_gtkagg', '_tkagg', 'PyQt4.uic.port_v3', 'Tkconstants', 'Tkinter', 'tcl'],
'dll_excludes': ['libgdk-win32-2.0-0.dll',
'libgdk_pixbuf-2.0-0.dll',
'libgobject-2.0-0.dll',
'tcl85.dll',
'tk85.dll'],
'skip_archive': True },}
setup(console=['test_mpl.py'], options=options)
</code></pre>
<hr/>
<p>输出为:</p>
<pre><code>running py2exe
*** searching for required modules ***
Traceback (most recent call last):
File "setup2.py", line 23, in <module>
setup(console=['test_mpl.py'], options=options)
File "C:\Python27\lib\distutils\core.py", line 152, in setup
dist.run_commands()
File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 243, in run
self._run()
File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 296, in _run
self.find_needed_modules(mf, required_files, required_modules)
File "C:\Python27\lib\site-packages\py2exe\build_exe.py", line 1308, in find_needed_modules
mf.import_hook(f)
File "C:\Python27\lib\site-packages\py2exe\mf.py", line 719, in import_hook
return Base.import_hook(self,name,caller,fromlist,level)
File "C:\Python27\lib\site-packages\py2exe\mf.py", line 136, in import_hook
q, tail = self.find_head_package(parent, name)
File "C:\Python27\lib\site-packages\py2exe\mf.py", line 204, in find_head_package
raise ImportError, "No module named " + qname
ImportError: No module named mpl_toolkits
</code></pre>