cx_Freeze TypeError dist必须是Distribution实例

问题描述 投票:0回答:2

我没有使用cx_Freeze的安装文件找到有关此问题的特定主题。我正在尝试为我的程序创建一个exe,但有些东西与distutils不相符。我无法找到此库的更新whl所以我不确定是否有一个已知的修复程序。

程序运行正常,没有错误。

有谁知道为什么这个问题存在。请注意我无法在我的工作网络中使用pip所以我必须使用whl,tar.gz'和egg文件来安装库。这就是为什么我要为whl找到更新的distutils文件的原因。

我的setup.py文件。

from cx_Freeze import setup, Executable

base = None    

build_exe_options = {'packages': ['idna',
                                  'json',
                                  'tkinter',
                                  'operator',
                                  'clipboard',
                                  'matplotlib',
                                  'tkinter.ttk ',
                                  'matplotlib.pyplot',
                                  'matplotlib.backends.backend_tkagg'],
                     'include_files': ['tracker1.json', 'tracker2.json']}

setup(
    name='<NAME>',
    options={'build.exe': build_exe_options},
    version='<0.2>',
    description='<some random desc>',
    executables=[Executable('MAIN.py', base=base)]
)

错误:

"C:\Users\user_name\Desktop\Python 3.6.2\python.exe" "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.2.3\helpers\pycharm\pycharm_setup_runner.py" "C:\Users\user_name\Desktop\Python Work Projects\GATE\setup.py"
Testing started at 2:55 PM ...
Traceback (most recent call last):
running pycharm_test
  File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.2.3\helpers\pycharm\pycharm_setup_runner.py", line 26, in <module>
    exec (fh.read(), globals(), locals())
  File "<string>", line 21, in <module>
  File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\cx_Freeze\dist.py", line 349, in setup
    distutils.core.setup(**attrs)
  File "C:\Users\user_name\Desktop\Python 3.6.2\lib\distutils\core.py", line 148, in setup
    dist.run_commands()
  File "C:\Users\user_name\Desktop\Python 3.6.2\lib\distutils\dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "C:\Users\user_name\Desktop\Python 3.6.2\lib\distutils\dist.py", line 972, in run_command
    cmd_obj = self.get_command_obj(command)
  File "C:\Users\user_name\Desktop\Python 3.6.2\lib\distutils\dist.py", line 847, in get_command_obj
    cmd_obj = self.command_obj[command] = klass(self)
  File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\setuptools\__init__.py", line 147, in __init__
    _Command.__init__(self, dist)
  File "C:\Users\user_name\Desktop\Python 3.6.2\lib\distutils\cmd.py", line 57, in __init__
    raise TypeError("dist must be a Distribution instance")
TypeError: dist must be a Distribution instance
python matplotlib cx-freeze
2个回答
0
投票

尝试使用例如更新setuptools来自setuptools‑40.8.0‑py2.py3‑none‑any.whlGohlke's Windows binaries另见TypeError: dist must be a Distribution instance


0
投票

在我将文件编译成exe之后经过大量挖掘和处理几个错误之后我修复了我的问题。

问题的大部分与setup.py有关。我必须添加一些东西才能使它全部正确编译。

新的setup.py文件:

from cx_Freeze import setup, Executable
import os
base = "Win32GUI" # this lets the exe run without the console popping up.

# I had to add these 2 in order for tkinter to compile properly
os.environ['TCL_LIBRARY'] = r'C:\Users\user_name\Desktop\Python3.6.2\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\user_name\Desktop\Python3.6.2\tcl\tk8.6'

# eventhough numpy is not part of my main imports in my MAIN file I still needed to 
# provide 'numpy.core._methods' and 'numpy.lib.format' in the packages list for 
# my plot to work. I am assuming it is because `matplotlib` is using `numpy` somewhere.
build_exe_options = {'packages': ['numpy.core._methods',
                                  'numpy.lib.format',
                                  'idna',
                                  'json',
                                  'tkinter',
                                  'operator',
                                  'clipboard',
                                  'matplotlib',
                                  'tkinter.ttk',
                                  'matplotlib.pyplot',
                                  'matplotlib.backends.backend_tkagg'],
                     'include_files': [r'tracker1.json',
                                       r'tracker2.json',
                                       "tcl86t.dll",
                                       "tk86t.dll"]}
# On jpeg's advice I changed build.exe to build_exe though I am not sure what the change was for.
setup(
    name='<CCC>',
    options={'build_exe': build_exe_options},
    version='<0.2>',
    description='<CCC - Copy Count Chart!.>',
    executables=[Executable(r'C:\path\MAIN.py', base=base)]
)

之后我不得不在CMD中运行build命令,否则我最终会在IDE控制台中出错。

我不知道为什么,但它接缝需要使用命令提示符符合setup.py文件,否则它就不会工作。

如果有其他人需要它,这是命令:

python setup.py build

请记住,您可能需要使用完整的文件路径来使用安装文件。我必须使用以下命令设置我的工作目录:

python "C:\Users\user_name\Desktop\Python Work Projects\PROJECT\setup.py" build
© www.soinside.com 2019 - 2024. All rights reserved.