Creating executable with Py2exe and matplotlib errors

时光毁灭记忆、已成空白 提交于 2019-12-08 06:23:58

问题


I have been searching this forum and many others and cannot seem to get a good method of creating an executable. I have tried several different methods (py2exe, pyinstaller and cx_freeze) and all seem to give me some kind of error.

When i tried pyinstaller, I received the error that "no _imaging C module is installed". Everything I search says that it has to do with PIL, but my code is not using PIL.

When I tried py2exe, I keep receiving the following error:

File "Scout_Tool.py", line 18, in <module>
File "matplotlib\pyplot.pyc", line 95, in <module>
File "matplotlib\backends\__init__.pyc", line 25, in pylab_setup
ImportError: No module named backend_qt4agg

I am at a loss of what to do. My code contains the following imports:

import os
import csv
import wx
import time
import math

from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.pyplot import figure,show
from mpl_toolkits.basemap import Basemap
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from numpy.random import rand
from datetime import datetime
import wx.calendar as cal
import numpy as npy
from pylab import *
import numpy as np
import matplotlib
import adodbapi
import sqlparse
import pylab
import annote_new
import cPickle as pickle

Does anyone have any suggestions on how to do a build of the executable using py2exe? What i have tried...

from distutils.core import setup 
import py2exe 
import matplotlib 

setup( 
    windows=[{'script': r'Scout_Tool.py'}], 

    data_files=matplotlib.get_py2exe_datafiles(), 

    options={
        r'py2exe': {
            r'includes': r'ElementConfig', 
            r'includes': r'ColorConv', 
            r'includes': r'Tkinter', 
            r'includes': r're', 
            r'includes': r'math', 
            r'includes': r'sys', 
            r'includes': r'matplotlib', 
            r'includes': r'mpl_toolkits',
            r'includes': r'matplotlib.backends.backend_wx',
            r'dll_excludes': [r'MSVCP90.dll'], 
        }
    }, 

) 

Thanks for any help!


回答1:


I am not fully sure this will fix your problem, but you should start by correcting that faulty options dictionary entry. In python, when you define a dictionary with the same key over and over, you are only going to get the last value. A key can only exist once:

options={
    r'py2exe': {
        r'includes': r'ElementConfig', 
        ...
        r'includes': r'mpl_toolkits',
        r'includes': r'matplotlib.backends.backend_wx',
        ...
    }
} 

print options
#{'py2exe': {'includes': 'matplotlib.backends.backend_wx'}}

I suspect the result of this usage is py2exe not really finding any of your intended includes. includes should be a list:

options={
    'py2exe':{
        'includes': [
            'ElementConfig',
            'ColorConv',
            'Tkinter',
            're',
            'math',
            'sys',
            'matplotlib',
            'mpl_toolkits',
            'matplotlib.backends.backend_wx'
        ],
        'dll_excludes': ['MSVCP90.dll'], 
    }
},

If after this, it still complains about the backend missing, you can add another explicit entry:

        'includes': [
            ...
            'matplotlib.backends.backend_qt4agg'
        ],


来源:https://stackoverflow.com/questions/11231579/creating-executable-with-py2exe-and-matplotlib-errors

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