我尝试了很多方法,但我做的大多数代码(例如打印“f”)都运行良好。我不确定为什么我的代码在 exe 中不起作用。以下是我得到的错误
from distutils.core import setup
import py2exe
setup(
windows=[{'script': 'hello.py'}],
options={
'py2exe':
{
'includes': ['lxml.etree', 'lxml._elementpath', 'gzip'],
}
}
)
错误我得到了 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
请您参考如下方法:
这是 py2exe 的一个已知问题,请参阅 http://www.py2exe.org/index.cgi/MatPlotLib
创建 bundle 时,py2exe 要求您指定需要的任何外部文件。
如果您正在寻找更自动化的东西,请查看 pyinstaller项目(许多常用库已经处理 - 不是魔术,而是因为作者和贡献者已经注意指定许多常用 python 库需要哪些外部文件)。
