pyinstaller - pyinstaller ImportError: C extension: No module named np_datetime not built
问题描述
I am running a virtual environment with Python 2.7 for my program. There seems to be a problem after creating the executable file on windows. I ran venv/Scripts/pyinstaller.exe -F main.py everything seems fine. But when i click on the created executable main.exe. There is an error.
Tried and tested
- I have re-installed of pandas and pyinstaller
- Implemented the hook-pandas.py to the hooks folder in the environment. hook-pandas
- Ensured the environment is activated.
- Checked that the program is running fine before building executable.
- Re-created the environment.
Yet after all that, I am prompted with this issue [see Importerror] when I run the executable file.
It is an extreme pain to debug this because the command prompt displaying the error will not pause but close almost immediately.
Looking for Suggestions I am hoping for suggestions to troubleshoot Pyinstaller. Any resources to read up on would be nice. Usually, I have no trouble with python as Pycharm has several handy debugging tools that will help me identify the problem
解决方案
我遇到了同样的问题并找到了这个线程,但我设法从你发布的参考资料中解决了它(关于pandas._libs.tslibs.timedeltas
),所以谢谢你!
ImportError
在那篇文章中,实际上pandas._libs.tslibs.timedeltas
,如果您查看发布者的日志,则导致的模块是。但是你和我遇到的错误是指代的np_datetime
。所以,从回溯日志中,我终于知道我们要写的代码hook-pandas.py
应该是这样的:
hiddenimports = ['pandas._libs.tslibs.np_datetime']
也许仅此一项就可以解决您的问题,但是,就我而言,一旦我解决了该np_datetime
问题,就会出现其他非常相似的ImportError
问题(也与有关 pandas 的 hiddenimports 相关),因此,如果您遇到相同的问题,只需定义hiddenimports
如下:
hiddenimports = ['pandas._libs.tslibs.np_datetime','pandas._libs.tslibs.nattype','pandas._libs.skiplist']
TL;博士:
你可以先尝试写
hiddenimports = ['pandas._libs.tslibs.np_datetime']
进入hook-pandas.py
. 但是,如果由于某种原因您遇到了我后来遇到的完全相同的问题,请尝试
hiddenimports = ['pandas._libs.tslibs.np_datetime','pandas._libs.tslibs.nattype','pandas._libs.skiplist']
如果您想深入了解(或遇到与ImportError
我不同的 pandas),这是__init__.py
您的回溯日志中引用的 pandas 中的代码(第 23 到 35 行):
from pandas.compat.numpy import *
try:
from pandas._libs import (hashtable as _hashtable,
lib as _lib,
tslib as _tslib)
except ImportError as e: # pragma: no cover
# hack but overkill to use re
module = str(e).replace('cannot import name ', '')
raise ImportError("C extension: {0} 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.".format(module))
从此我进入了
C:\Python27\Lib\site-packages\pandas_libs
和
C:\Python27\Lib\site-packages\pandas_libs\tslibs
文件夹并找到导致错误的模块的确切名称。
我希望这能解决你的问题,就像我的问题一样。
干杯!
推荐阅读
- mysql - 带有查询字符串的 MySQL 过程
- regex - 如何在较长的段落中为该句子编写正则表达式模式?
- express - 从控制器获取 multerS3 密钥
- java - 方法参数获取所有输入,而不仅仅是双输入
- c - MAX6675 与 PIC18F45k22 通过 UART 数据传输问题
- java - Maven 构建/插件部分继承行为 wrt 到插件版本
- unit-testing - 乔·阿姆斯特朗 (Joe Armstrong) 所说的单元测试“有更先进的技术”指的是什么
- sql - Big Query 循环遍历开始和结束日期
- sequelize.js - 理解如何解析/传递 sequelize 查找结果的问题
- javascript - 使用正则表达式删除字符串中的键值