【问题标题】:PyInstaller ModuleNotFoundPyInstaller 模块未找到
【发布时间】:2020-04-20 22:59:26
【问题描述】:

我一直在努力解决 PyInstaller 问题,但不确定如何修复 ModuleNotFound(特别是 pandas)。我的 .py 程序是一个简单的 onefile 脚本,它只导入 (Anaconda-)native 包(例如 tkinter、pandas、os),它在 IDE 中工作。我知道 PyInstaller 只导入顶级包,所以我将列出我目前的方法:

  1. 在虚拟环境中运行以将 Python 3.8 降级到 3.7.5。我听说人们对 Python 3.8 的 PyInstaller 有问题。还更新了最新版本的 PyInstaller。也试过没有环境。
  2. 从 onedir 而非 onefile 构建 pyinstaller --onedir myscript.py
  3. 将规范文件中的hiddenimports 更改为hiddenimports = ['pandas._libs.tslibs.timedeltas', etc.]hiddenimports = ['pandas']
  4. import pandas放在.py的顶部
  5. 关注这个:How can I add a Python site-package folder (that's not being included) to a PyInstaller spec file?,但将我的路径文件修复为C:\\Users\\username\\Anaconda\\lib,因为这是在 Anaconda 解释器中。然后它引发了AttributeError: module 'importlib._bootstrap_external' has no attribute '_w_long',我试图修复它无济于事

这些都没有奏效。有没有更好的方法可以在 Python 中构建可执行文件,或者是否有解决此问题的方法?

【问题讨论】:

  • @VikramadityaGaonkar 有趣的是,现在它引发了ImportError: Unable to import required dependencies: numpy: No module named 'numpy',而我从来没有在我的脚本中导入 numpy。我在 Anaconda 和 Python 库中都安装了 numpy。不知道为什么

标签: python pandas compilation pyinstaller


【解决方案1】:

我终于通过重新安装 pandas 和 numpy 来修复它。我没有想到这一点,因为我在此过程中多次重新安装了 pandas。无论如何,如果有人遇到同样的问题并需要最后的手段:

pip uninstall pandas -y pip uninstall numpy -y pip install pandas pip install numpy

编辑: 在此之后,我意识到我安装/连接 Anaconda 的方式很混乱,所以我重新安装了 Anaconda,pyinstaller 更容易使用。要在重新安装 Anaconda 后将 pyinstaller 与 Anaconda 一起使用而不是默认 python,conda install -c conda-forge pyinstaller

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-27
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 2020-11-26
    • 2021-01-02
    • 2023-01-05
    • 2013-02-13
    相关资源
    最近更新 更多