问题描述
Matplotlib可以在此应用程序中完美运行..但由于某种原因无法在内部版本中运行.为什么?
Matplotlib working in this app perfectly.. but not working in build for some reason. Why?
我会很乐意接受任何可以帮助我的建议.
I'll gladly take any advice that can help me.
.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行:
main.py is a script that I'm building. line #3 of it:
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=[]
)
点冻结:
..
matplotlib==1.3.1
numpy==1.8.2
..
python --version :
Python 2.7.6
推荐答案
好的,我没有找到解决此问题的合适方法.
Okay, I did not find proper solution for this problem.
我用肮脏的破解方法解决了,只需将venv中的distutils dir替换为系统python的distutils dir.现在一切正常,并且可以在venv中运行!对此不太清楚.
I solved it with dirty hack, by simply replacing distutils dir in venv by distutils dir of system python. Now it all working and it working in venv! Don't quite sure about drawbacks of that though.
据我了解,这个问题是venv的distutils确实很奇怪.似乎venvwrapper或/和python软件包由于某些原因更改了它,我不知道.
The issue as I can understand it, is that distutils of venv is really weird thing. Seems like venvwrapper or/and python packages changed it for some reasons, I don't know.
如果您对这种情况有所了解,请继续并将其添加到主题中作为答案或评论.:)
If you know something about this situation, please go ahead and add it to the thread as answers or comments. :)
这篇关于py2exe中的Matplotlib-ImportError:无法导入名称dist(文件"distutils \ __ init __.pyc")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!