简体   繁体   English

在使用py2exe时,使用Numpy会创建一个tcl文件夹

[英]Using Numpy creates a tcl folder when using py2exe

When using py2exe on my Python program I get an executable, but also a tcl\\ folder. 在我的Python程序上使用py2exe ,我得到一个可执行文件,但也是一个tcl\\文件夹。

This is strange, because I don't use tcl/tk at all and nothing related to tkinter in my code. 这很奇怪,因为我根本不使用tcl/tk ,在我的代码中没有任何与tkinter相关的东西。

Why importing numpy is responsible for adding this tcl\\ folder ? 为什么导入numpy负责添加这个tcl\\文件夹? How to prevent this to happen ? 如何防止这种情况发生?


test.py test.py

import numpy

print 'hello'

PY2EXE CODE PY2EXE代码

from distutils.core import setup
import py2exe

setup(script_args = ['py2exe'],   windows=[{'script':'test.py'}], options = {'py2exe': {'compressed':1,'bundle_files': 1}}, zipfile = None)

Modulefinder module which is used to determine dependencies gets "confused" and thinks you need Tkinter . 用于确定依赖关系的Modulefinder模块会“混淆”并认为您需要Tkinter

If you run following script... 如果您运行以下脚本...

from modulefinder import ModuleFinder

finder = ModuleFinder()
finder.run_script('test.py')
print finder.report()

...you will see found modules (shortened): ...你会看到找到的模块(缩短):

  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
...

So now we know that Tkinter is imported, but it is not very useful. 所以现在我们知道Tkinter是导入的,但它不是很有用。 The report does not show what is the offending module. 该报告未显示违规模块是什么。 However, it is enough information to exclude Tkinter by modifying py2exe script: 但是,通过修改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)

Usually that is enough. 通常这就足够了。 If you are still curious what modules are the offending ones, ModuleFinder is not much helpful. 如果您仍然对哪些模块是有问题的模块感到好奇, ModuleFinder并没有多大帮助。 But you can install modulegraph and its dependency altgraph . 但是你可以安装modulegraph及其依赖altgraph Then you can run the following script and redirect the output to a HTML file: 然后,您可以运行以下脚本并将输出重定向到HTML文件:

import modulegraph.modulegraph

m = modulegraph.modulegraph.ModuleGraph()
m.run_script("test.py")
m.create_xref()

You will get dependency graph, where you will find that: 您将获得依赖图,您将在其中找到:

numpy -> numpy.lib -> numpy.lib.utils -> pydoc -> Tkinter 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM