py2exe with matplotlib, numpy and pylab

穿精又带淫゛_ 提交于 2019-12-08 10:03:25

问题


I'm trying to generate an executable. the packages I am using are

import sys
import matplotlib.pyplot as plt
from pylab import *
from numpy import *  

the setup.py is the following

from distutils.core import setup
import py2exe
import matplotlib

setup(console=['<python file>'],data_files=matplotlib.get_py2exe_datafiles(),)   

but I get an error related to pyplot.pyc

Import Error: no module named backend_tkagg

any way around to fix it?


回答1:


You should include the matplotlib module explicitly. If you do that you can get some errors from unavailable dlls, so then you should exclude them.
A setup that works for me with your file:

from distutils.core import setup
import py2exe
import matplotlib

setup(console=['afile.py'],
      options={
               'py2exe': {
                          'packages' :  ['matplotlib', 'pytz'],
                          'dll_excludes': ['libgdk-win32-2.0-0.dll',
                                         'libgobject-2.0-0.dll',
                                         'libgdk_pixbuf-2.0-0.dll',
                                         'libgtk-win32-2.0-0.dll',
                                         'libglib-2.0-0.dll',
                                         'libcairo-2.dll',
                                         'libpango-1.0-0.dll',
                                         'libpangowin32-1.0-0.dll',
                                         'libpangocairo-1.0-0.dll',
                                         'libglade-2.0-0.dll',
                                         'libgmodule-2.0-0.dll',
                                         'libgthread-2.0-0.dll',
                                         'QtGui4.dll', 'QtCore.dll',
                                         'QtCore4.dll'
                                        ],
                          }
                },
      data_files=matplotlib.get_py2exe_datafiles(),)   



回答2:


I needed to add (python2.7):

    import sys
    sys.path.append("C:\\pathToYourPython\\pythonxy2731\\console\\Microsoft.VC90.CRT")


来源:https://stackoverflow.com/questions/11062417/py2exe-with-matplotlib-numpy-and-pylab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!