【发布时间】:2020-04-20 22:59:26
【问题描述】:
我一直在努力解决 PyInstaller 问题,但不确定如何修复 ModuleNotFound(特别是 pandas)。我的 .py 程序是一个简单的 onefile 脚本,它只导入 (Anaconda-)native 包(例如 tkinter、pandas、os),它在 IDE 中工作。我知道 PyInstaller 只导入顶级包,所以我将列出我目前的方法:
- 在虚拟环境中运行以将 Python 3.8 降级到 3.7.5。我听说人们对 Python 3.8 的 PyInstaller 有问题。还更新了最新版本的 PyInstaller。也试过没有环境。
- 从 onedir 而非 onefile 构建
pyinstaller --onedir myscript.py - 将规范文件中的
hiddenimports更改为hiddenimports = ['pandas._libs.tslibs.timedeltas', etc.]和hiddenimports = ['pandas'] - 将
import pandas放在.py的顶部 - 关注这个: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