Matplotlib完美地在这个应用程序中工作..但由于某种原因没有在构建中工作。为什么呢?
我很乐意接受任何可以帮助我的建议。
.exe.log :
Traceback (most recent call last):
File "main.py", line 3, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "matplotlib\__init__.pyc", line 103, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "distutils\__init__.pyc", line 25, in <module>
ImportError: cannot import name dist
main.py 是我正在构建的脚本。第3行:
import matplotlib
build.py :
# encoding: utf-8
import os
import sys
import errno
sys.path.append(os.path.abspath("."))
from distutils.core import setup
import shutil
import py2exe
import matplotlib as mpl
mpl.use('Agg')
distDir = 'dist'
shutil.rmtree('build', ignore_errors=True)
shutil.rmtree(distDir, ignore_errors=True)
try:
os.makedirs(distDir)
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(distDir):
pass
else:
raise
icon = 'icon.ico'
includes = ['matplotlib', 'numpy']
packages = ['matplotlib', 'pytz']
excludes = [
'_gtkagg', '_tkagg', 'bsddb', 'curses', 'email',
'pywin.debugger', 'pywin.debugger.dbgcon', 'pywin.dialogs',
'tcl', 'Tkconstants', 'Tkinter', 'sqlite3', 'doctest', 'test'
]
dll_excludes = [
'libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'libgdk_pixbuf-2.0-0.dll',
'tcl84.dll', 'tk84.dll', 'w9xpopen.exe'
]
data_files = mpl.get_py2exe_datafiles()
class Target(object):
def __init__(self, **kw):
self.__dict__.update(kw)
icon_resources = [(0, icon)]
GUI2Exe_Target = Target(
script='main.py',
dest_base='app_name',
name='app_name',
company_name='company_name',
copyright='company_name',
version='0.0.1',
icon_resources=icon_resources,
bitmap_resources=[],
other_resources=[]
)
setup(
options={
"py2exe": {
"compressed": 1,
"optimize": 0,
"includes": includes,
"excludes": excludes,
"packages": packages,
"dll_excludes": dll_excludes,
"bundle_files": 1,
"dist_dir": distDir,
"skip_archive": False,
"xref": False,
"ascii": False,
"custom_boot_script": '',
}
},
zipfile=None,
data_files=data_files,
console=[],
windows=[GUI2Exe_Target],
service=[],
com_server=[],
ctypes_com_server=[]
)
pip冻结:
..
matplotlib==1.3.1
numpy==1.8.2
..
python --version :
Python 2.7.6
答案 0 :(得分:3)
好的,我没有找到解决此问题的正确方法。
我用脏黑客解决了这个问题,只需用system python的distutils dir替换venv中的distutils dir即可。现在一切正常,它在venv中工作! 不太确定这方面的缺点。
我能理解的问题是,对于venv的困扰是非常奇怪的。看起来像venvwrapper或/和python包由于某些原因改变了它,我不知道。
如果您对此情况有所了解,请继续将其作为答案或评论添加到主题中。 :)