python - ImportError: No module named mpl_toolkits with maptlotlib 1.3.0 and py2exe -
i can't figure out how able package via py2exe now:
i running command:
python setup2.py py2exe
via python 2.7.5 , matplotlib 1.3.0 , py2exe 0.6.9 , 0.6.10dev
this worked matplotlib 1.2.x
i have read http://www.py2exe.org/index.cgi/exewitheggs , tried implement suggestions handling mpl_toolkits since it's having become namespace package.
i'm trying answer here too: http://matplotlib.1069221.n5.nabble.com/1-3-0-and-py2exe-regression-td41723.html
adding empty __init__.py
mpl_toolkits makes work, workaround problem.
can suggest need make py2exe work mpl_toolkits.axes_grid1 in matplotlib 1.3.0 ?:
test_mpl.py is:
from mpl_toolkits.axes_grid1 import make_axes_locatable, axes_size if __name__ == '__main__': print make_axes_locatable, axes_size
setup2.py is:
import py2exe import distutils.sysconfig distutils.core import setup # attempts 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 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)
output is:
running py2exe *** searching 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
there quite simple workaround problem. find directory mpl_tools imported , add empty text file named __init__.py
in directory. py2exe find , include module without special imports needed in setup file.
you can find mpl_tools directory typing following in python console:
import importlib importlib.import_module('mpl_toolkits').__path__
i found solution here https://stackoverflow.com/a/11632115/2166823 , seems apply namespace packages in general.
Comments
Post a Comment