用于确定依赖关系的Modulefinder 模块“混淆”并认为您需要Tkinter。
如果您运行以下脚本...
from modulefinder import ModuleFinder
finder = ModuleFinder()
finder.run_script('test.py')
print finder.report()
...你会看到找到的模块(缩短):
Name File
---- ----
m BaseHTTPServer C:\Python27\lib\BaseHTTPServer.py
m ConfigParser C:\Python27\lib\ConfigParser.py
m FixTk C:\Python27\lib\lib-tk\FixTk.py
m SocketServer C:\Python27\lib\SocketServer.py
m StringIO C:\Python27\lib\StringIO.py
m Tkconstants C:\Python27\lib\lib-tk\Tkconstants.py
m Tkinter C:\Python27\lib\lib-tk\Tkinter.py
m UserDict C:\Python27\lib\UserDict.py
m _LWPCookieJar C:\Python27\lib\_LWPCookieJar.py
...
所以现在我们知道Tkinter 是导入的,但它不是很有用。该报告没有显示有问题的模块是什么。但是,通过修改 py2exe 脚本排除Tkinter 的信息就足够了:
from distutils.core import setup
import py2exe
setup(script_args = ['py2exe'],
windows=[{'script':'test.py'}],
options = {'py2exe': {'compressed':1,
'bundle_files': 1,
'excludes': ['Tkconstants', 'Tkinter']
},
},
zipfile = None)
通常这就足够了。如果您仍然好奇哪些模块是有问题的模块,ModuleFinder 并没有多大帮助。但是您可以安装modulegraph 及其依赖项altgraph。然后您可以运行以下脚本并将输出重定向到 HTML 文件:
import modulegraph.modulegraph
m = modulegraph.modulegraph.ModuleGraph()
m.run_script("test.py")
m.create_xref()
你会得到依赖图,你会发现:
numpy -> numpy.lib -> numpy.lib.utils -> pydoc -> Tkinter