簡體   English   中英

在使用py2exe時,使用Numpy會創建一個tcl文件夾

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

在我的Python程序上使用py2exe ,我得到一個可執行文件,但也是一個tcl\\文件夾。

這很奇怪,因為我根本不使用tcl/tk ,在我的代碼中沒有任何與tkinter相關的東西。

為什么導入numpy負責添加這個tcl\\文件夾? 如何防止這種情況發生?


test.py

import numpy

print 'hello'

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模塊會“混淆”並認為您需要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 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM