【问题标题】:cx_Freeze TypeError dist must be a Distribution instancecx_Freeze TypeError dist 必须是 Distribution 实例
【发布时间】:2019-02-18 21:17:23
【问题描述】:

我没有在 cx_Freeze 的安装文件中找到有关此问题的特定主题。 我正在尝试为我的程序创建一个 exe,但 distutils 的某些内容并不正确。我无法找到此库的更新 whl,因此我不确定是否有已知的修复方法。

程序运行良好,没有错误。

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

我的 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

【问题讨论】:

  • 您使用的是哪个版本的cx_Freeze
  • 您实际运行哪个命令来调用设置脚本?还有一件事:options 字典键应该是 'build_exe',而不是 'build.exe'
  • @jpeg 嘿,感谢 cmets。我之前使用过 build.exe,它运行良好。此外,我正在使用来自 PyPi 站点的最新发布版本 cx_Freeze 5.1.1。有一个预发布版本,但我倾向于只使用完整版本以避免出现问题。
  • 就使用build.exe 而言:根据我的尝试,可以毫无错误地调用设置脚本,但在没有选项传递给@987654336 的意义上它不起作用然后@命令。就使用cx_Freeze 5.1.1 而言,这很好。我之所以问,是因为cx_Freeze 5.0.1 引入了 Python 3.6 支持,如果您使用的是早期版本,那可能是与 cx_Freeze 的兼容性问题。
  • 你为什么坚持使用matplotlib标签?我真的没有看到你的问题的相关性。

标签: python matplotlib cx-freeze


【解决方案1】:

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

【讨论】:

  • 很遗憾,我无法下载链接中的 whl。我的工作防火墙不允许我这样做。
  • 嗯...是否可以选择使用另一个网络中的另一台计算机下载它并将其邮寄到您的工作帐户(如果防火墙允许)或将其放在 U 盘上(如果公司政策允许您)?
  • 不。防火墙会删除所有 zip 文件和任何可以被视为代码的内容以及 USB 端口都被禁用。这令人沮丧。我正在为工作构建这个应用程序,但是工作不允许我下载我需要的文件,哈哈。
  • 听起来很沮丧,我不知道如何进一步帮助。顺便说一句,我链接的资源本身是非官方的,但被广泛使用,经常会遇到指向它的链接;例如,我们也在我工作的公司中使用这些轮子。
  • 来自 windows 二进制链接?
【解决方案2】:

在我将文件编译为 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 中运行构建命令,否则我最终会在我的 IDE 控制台中出现错误。

我不知道为什么,但它似乎需要使用命令提示符来运行 setup.py 文件,否则它将无法正常工作。

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

python setup.py build

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

python "C:\Users\user_name\Desktop\Python Work Projects\PROJECT\setup.py" build

【讨论】:

    【解决方案3】:

    我遇到了类似的问题,已通过在顶部添加 import setuptools 来解决。我认为它纠正了cx_Freeze 中的一些导入,但我不确定它是否相关。

    import setuptools
    from cx_Freeze import setup, Executable
    
    ...
    

    这在不添加 'numpy.core._methods', 'numpy.lib.format' 的情况下也有效。

    【讨论】:

      猜你喜欢
      • 2014-02-03
      • 1970-01-01
      • 2019-03-21
      • 2021-04-08
      • 2018-12-09
      • 2012-05-04
      • 1970-01-01
      • 1970-01-01
      • 2021-10-18
      相关资源
      最近更新 更多