2013-12-10 59 views
2

我尝试了很多方法,但我为例如print“f”做的大多数代码运行良好。我不知道为什么我的代码不能在exe中工作。以下是错误我得到无法工作py2exe

from distutils.core import setup 
import py2exe 

setup(
    windows=[{'script': 'hello.py'}], 
    options={ 
     'py2exe': 
     { 
      'includes': ['lxml.etree', 'lxml._elementpath', 'gzip'], 
     } 
    } 
) 

enter image description here

错误,我得到hello.exe.log

Traceback (most recent call last): 
File "hello.py", line 25, in <module> 
File "matplotlib\__init__.pyc", line 765, in <module> 
File "matplotlib\__init__.pyc", line 683, in rc_params 
File "matplotlib\__init__.pyc", line 599, in matplotlib_fname 
File "matplotlib\__init__.pyc", line 246, in wrapper 
File "matplotlib\__init__.pyc", line 520, in _get_data_path_cached 
File "matplotlib\__init__.pyc", line 516, in _get_data_path 
RuntimeError: Could not find the matplotlib data files 
Traceback (most recent call last): 
File "hello.py", line 25, in <module> 
File "matplotlib\__init__.pyc", line 765, in <module> 
File "matplotlib\__init__.pyc", line 683, in rc_params 
File "matplotlib\__init__.pyc", line 599, in matplotlib_fname 
File "matplotlib\__init__.pyc", line 246, in wrapper 
File "matplotlib\__init__.pyc", line 520, in _get_data_path_cached 
File "matplotlib\__init__.pyc", line 516, in _get_data_path 
RuntimeError: Could not find the matplotlib data files 

这是我使用的LIB,是它的一些库不工作以及与py2exe ?

###### IMPORT STATEMENTS ###################################### 
import csv 
import webbrowser 
import heapq 
from math import floor 
import os 
from os.path import basename, splitext 
import re 
from scipy import * 
import string 
import sys 
from time import sleep 
import time 
import zipfile 

from StringIO import StringIO 
from Tkinter import * 
import Tkinter as Tk 
import lxml.etree as et 
import matplotlib.cm as cm 
from matplotlib.collections import PatchCollection 
from matplotlib.patches import Rectangle, Circle, RegularPolygon 
from matplotlib.pyplot import * 
import matplotlib.pyplot as pl 
import matplotlib.pyplot as plt 
import matplotlib.pyplot as plt 
import matplotlib.pyplot as plt 
from matplotlib.ticker import NullFormatter 
from mpl_toolkits.axes_grid1 import host_subplot 
import mpl_toolkits.axisartist as AA 
import numpy as np 
from pylab import * 
import pylab as pl 
import pylab as plot 
from scipy.integrate import simps 
import tkFileDialog 
from tkFont import Font 
import tkMessageBox 
from scipy import interpolate 
import pylab as py 
import sys 

回答

3

这与py2exe一个已知的问题,请参见http://www.py2exe.org/index.cgi/MatPlotLib

在创建包py2exe需要指定,将需要任何外部文件。

如果你正在寻找更自动的东西,看看pyinstaller项目(其中很多公共库已经处理 - 不是通过魔术,而是因为作者和贡献者已经小心指定了很多需要的外部文件常用的python库)。

+0

如何在我不确定哪一个实际需要时指定外部文件?<。抱歉,我是一个Python编程新手.. @ 6502 – user2837162

+0

@ ZhenHui:这个问题没有简单的解决方案。在一个理想的世界中,图书馆作者可以明确地指定所有的运行时依赖关系,以允许打包软件创建工作包。 pyinstaller目前的解决方案(即让包装软件知道所有库)是IMO更难:pyinstaller是一种非常棒的软件(绝大部分时间都是正常工作)和噩梦来编写和保持。 Py2exe解决方案是为了减轻最终用户的负担。 – 6502