【问题标题】:Pyinstaller ImportError: cannot import name 'dist' on WindowsPyinstaller ImportError:无法在 Windows 上导入名称“dist”
【发布时间】:2019-02-11 12:28:25
【问题描述】:

我正在尝试使用 Pyinstaller(3.3 版)在 Windows(8.1 版)上将 Python(3.6 版)项目构建到单个 exe 文件中。该项目包括 PyQt5、numpy、matplotlib 依赖项。 Pyinstaller 写道:

Building EXE from out00-exe.toc completed successfully.

但是当我运行 exe 文件时,我得到:

...
  File "distutils\__init__.py", line 44, in <module>
ImportError: cannot import name 'dist'
[6748] Failed to execute script myproj

第 44 行的文件 "distutils\__init__.py" 包含导入:

from distutils import dist, sysconfig  # isort:skip

这个项目可以毫无问题地在 Ubuntu 上构建并且运行良好。我尝试添加隐藏的导入:

'distutils',
'distutils.dist',
'dist',

没用。

为什么这个错误会出现在 Windows 上以及如何修复它?

【问题讨论】:

    标签: python windows pyinstaller importerror


    【解决方案1】:

    尝试在 Windows 7 64 位上构建 Django 项目(不是 PyQT)时出现相同的错误消息。我用PyInstaller 3.4

    在我的情况下,问题通过降级到Python 3.5(我使用其他 Python 版本创建了一个新的 anaconda 环境)解决了,然后它开始工作。

    我不知道它是否对你有用,但它对我有用。

    【讨论】:

    • 感谢您分享您的经验。我已经仔细尝试过,但它对我不起作用......我遇到了与问题中提到的相同的错误。
    • 这里有什么新见解吗? @Ralf,您使用的是哪个 Python 版本?我尝试了 3.5.4 但得到了同样的错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-25
    • 1970-01-01
    • 1970-01-01
    • 2013-03-13
    • 1970-01-01
    • 2020-11-13
    • 1970-01-01
    相关资源
    最近更新 更多