pyinstaller ImportError:C扩展名:没有构建名为np_datetime的模块

Muz*_*mir 6 pyinstaller timedelta

我正在为我的程序运行Python 2.7的虚拟环境.在Windows上创建可执行文件后似乎有问题.我跑了venv/Scripts/pyinstaller.exe -F main.py 一切似乎都没问题.但是当我点击创建的可执行文件main.exe时.有一个错误.

试过并测试过

  1. 我已经重新安装了pandas和pyinstaller
  2. 将hook-pandas.py实现到环境中的hooks文件夹. 钩大熊猫
  3. 确保环境被激活.
  4. 在构建可执行文件之前检查程序运行正常.
  5. 重新创造了环境.

然而,毕竟,当我运行可执行文件时,我被提示有这个问题[请参阅Importerror].

在此输入图像描述

调试它是一件非常痛苦的事情,因为显示错误的命令提示符不会暂停但几乎立即关闭.

类似的问题

寻找建议 我希望有关解决Pyinstaller的建议.任何阅读资源都会很好.通常,我对python没有任何问题,因为Pycharm有几个方便的调试工具,可以帮助我识别问题

小智 16

我遇到了同样的问题并找到了这个帖子,但是我设法从你发布参考资料(大约pandas._libs.tslibs.timedeltas)中借用它来解决它,所以谢谢你!

在那篇文章中,ImportError实际上pandas._libs.tslibs.timedeltas,如果您查看海报的日志,那么产生该模块的模块就是这样.但是你和我遇到的错误指的是np_datetime.因此,从追溯日志中,我终于发现我们要编写的代码hook-pandas.py应该如下:

hiddenimports = ['pandas._libs.tslibs.np_datetime']
Run Code Online (Sandbox Code Playgroud)

也许只有这一点才能解决你的问题,在我的情况下,一旦我解决了np_datetime问题,就会出现其他非常类似的ImportError问题(也与关于熊猫的隐藏导入有关),所以,如果你遇到同样的问题,只需定义hiddenimports如下:

hiddenimports = ['pandas._libs.tslibs.np_datetime','pandas._libs.tslibs.nattype','pandas._libs.skiplist']
Run Code Online (Sandbox Code Playgroud)

TL; DR:

你可以先试着写

hiddenimports = ['pandas._libs.tslibs.np_datetime']
Run Code Online (Sandbox Code Playgroud)

进入hook-pandas.py.但是,如果由于某种原因你遇到了我之后做的完全相同的问题,请尝试

hiddenimports = ['pandas._libs.tslibs.np_datetime','pandas._libs.tslibs.nattype','pandas._libs.skiplist']
Run Code Online (Sandbox Code Playgroud)

如果你想深入潜水(或者遇到不同于ImportError我做过的熊猫),这就是__init__.py你的追溯记录中引用的熊猫代码(第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))
Run Code Online (Sandbox Code Playgroud)

从那以后我进入了

C:\ Python27\LIB \站点包\ pandas_libs

C:\ Python27\LIB \站点包\ pandas_libs\tslibs

文件夹并找到导致错误的模块的确切名称.

我希望能像我一样解决你的问题.

干杯!