我编写了一个简单的python脚本,我现在正在尝试创建一个exe文件。每当我尝试运行生成的exe时,程序在import pandas
失败,我收到以下错误。
Traceback (most recent call last):
File "myProgram.py", line 14, in <module>
import pandas
File "c:\temp\pip-install-k4pegh\pyInstaller\PyInstaller\loader\pyimod03_importers.py", line 396, in load_module
File "site-packages\pandas\__init__.py", line 35, in <module>
ImportError: C extension: No module named tslib not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
[492] Failed to execute script myProgram
查看cmd输出,加载了hook-pandas。所以这不是pyinstaller找到pandas钩子的问题。
30240 INFO: Loading module hook "hook-pkg_resources.py"...
30568 INFO: Processing pre-safe import module hook win32com
31036 INFO: Loading module hook "hook-pytz.py"...
31286 INFO: Loading module hook "hook-pywintypes.py"...
31550 INFO: Loading module hook "hook-setuptools.py"...
31644 INFO: Loading module hook "hook-encodings.py"...
33516 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
33516 INFO: Loading module hook "hook-numpy.core.py"...
33609 INFO: Loading module hook "hook-sqlite3.py"...
33796 INFO: Loading module hook "hook-pandas.py"...
33812 INFO: Loading module hook "hook-win32com.py"...
34779 INFO: Loading module hook "hook-pythoncom.py"...
35217 INFO: Analyzing run-time hooks ...
35231 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
35247 INFO: Including run-time hook 'pyi_rth__tkinter.py'
35263 INFO: Including run-time hook 'pyi_rth_pkgres.py'
35279 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
我必须自己添加pandas-hook到Python27\Lib\site-packages\PyInstaller\hooks
。请参阅No module named 'pandas._libs.tslibs.timedeltas' in PyInstaller和https://github.com/lneuhaus/pyinstaller/commit/017b247064f9bd51a620cfb2172c05d63fc75133。这可能是个问题吗?
之前我还尝试根据这个问题PyInstaller and Pandas更改spec文件,但没有运气。
使用:
python 2.7
pyinstaller 3.3.1
pandas 0.22.0.
如果有人知道为什么pyinstaller不能使用加载的钩子或者有什么想法接下来尝试,我会非常感激。