【问题标题】:ValueError: numpy.ufunc size changed, may indicate binary incompatibility. Expected 216 from C header, got 192 from PyObjectValueError:numpy.ufunc 大小已更改,可能表示二进制不兼容。预期来自 C 标头的 216,从 PyObject 获得 192
【发布时间】:2020-06-04 23:32:54
【问题描述】:

在 jupyter notebook 中,我遇到了这个错误。我正在使用 py 我刚刚安装了pytorch,以前它工作正常。

import pyodbc
import pandas as pd
import matplotlib.pyplot as plt

import warnings
warnings.filterwarnings('ignore')

当我运行上述单元格时,出现以下错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-1051f624fd0e> in <module>()
      1 import pyodbc
----> 2 import pandas as pd
      3 import matplotlib.pyplot as plt
      4 
      5 import warnings

C:\Anaconda3\lib\site-packages\pandas\__init__.py in <module>()
     29 
     30 try:
---> 31     from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib
     32 except ImportError as e:  # pragma: no cover
     33     # hack but overkill to use re

C:\Anaconda3\lib\site-packages\pandas\_libs\__init__.py in <module>()
      1 # flake8: noqa
      2 
----> 3 from .tslibs import (
      4     NaT,
      5     NaTType,

C:\Anaconda3\lib\site-packages\pandas\_libs\tslibs\__init__.py in <module>()
      1 # flake8: noqa
      2 
----> 3 from .conversion import localize_pydatetime, normalize_date
      4 from .nattype import NaT, NaTType, iNaT, is_null_datetimelike
      5 from .np_datetime import OutOfBoundsDatetime

__init__.pxd in init pandas._libs.tslibs.conversion()

ValueError: numpy.ufunc size changed, may indicate binary incompatibility. Expected 216 from C header, got 192 from PyObject

【问题讨论】:

    标签: python pandas numpy


    【解决方案1】:

    您安装了哪个版本的numpy?我在1.18.5 上遇到了同样的错误,降级到1.16.01.16.1 解决了issue。 还要检查pytorch 需要哪个numpy 版本,以及需要numpy 的任何其他库,我发现pipdeptree 对此非常有用。

    【讨论】:

    • 我在 Python3.6 中使用 numpy==1.19.5 和在 Python3.7 中使用 numpy==1.20.0,但在 Python3.8 中使用 numpy==1.20.0 时收到相同的警告而 Python3.9 的警告消失了。
    • @ÁlvaroMondéjar 这是一个“警告”吗??
    【解决方案2】:

    我遇到了同样的错误,通过升级 Numpy 解决了

    pip uninstall numpy ----> 运行 2-3 次,直到看到“numpy not found”

    通过简单的 pip 安装最新的 Numpy

    pip install numpy 
    

    【讨论】:

    • 您可能想要添加特定的新版本,因为在另一个答案中建议降级。我会用,pip install numpy==1.16.1
    【解决方案3】:

    我得到了同样的错误,但我有 numpy 14.x。当我升级到 1.16.6 时,错误就消失了。 pip install numpy==1.16.6

    【讨论】:

      【解决方案4】:

      想补充一点,我通过从 python 3.6 升级到 python3.8 并安装 numpy 1.20 为我的环境解决了这个问题

      您可能需要使用 pip cache purge 从 pip 清除缓存的软件包版本。

      【讨论】:

        【解决方案5】:

        更新 numpy 也可以解决其他答案中提到的这个问题。但是,从 quantipy3 (latest==0.2.4) 开始,要安装的 numpy 版本为 1.14.x。但我必须将它升级到 1.16.x 才能使 quantipy 工作。所以这就是我所做的。

        pip show -v numpy

        Name: numpy
        Version: 1.14.5
        Summary: NumPy: array processing for numbers, strings, records, and objects.
        Home-page: http://www.numpy.org
        Author: Travis E. Oliphant et al.
        Author-email: None
        License: BSD
        Location: /home/kusal/.local/lib/python3.8/site-packages
        Requires: 
        Required-by: scipy, quantipy3, pyarrow, pandas, azureml-dataset-runtime
        Metadata-Version: 2.1
        Installer: pip
        Classifiers:
          Development Status :: 5 - Production/Stable
          Intended Audience :: Science/Research
          Intended Audience :: Developers
          License :: OSI Approved
          Programming Language :: C
          Programming Language :: Python
          Programming Language :: Python :: 2
          Programming Language :: Python :: 2.7
          Programming Language :: Python :: 3
          Programming Language :: Python :: 3.4
          Programming Language :: Python :: 3.5
          Programming Language :: Python :: 3.6
          Programming Language :: Python :: Implementation :: CPython
          Topic :: Software Development
          Topic :: Scientific/Engineering
          Operating System :: Microsoft :: Windows
          Operating System :: POSIX
          Operating System :: Unix
          Operating System :: MacOS
        

        那么,

        pip uninstall numpy

        最后,

        pip install numpy==1.16.1

        Quantipy 会按预期给出错误,说 numpy 版本不兼容。但是对于我的用例,结果还可以。 (我正在使用 RIM 和 Dataset 模块)

        【讨论】:

          【解决方案6】:

          总是更好地创造一个新鲜的环境,尤其是当 theano 和 pymc3. 这是我的 Jupyter Notebook 的一部分,我尝试编写一个涉及贝叶斯推理上下文中的上述库/工具的示例。
          Full Notebook 可能很快就会在 GitHub 上发布,但现在,我希望以下内容可能会有所帮助:

          2。请务必遵循以下说明: 确保您遵循以下网址中的所有说明状态:

          https://github.com/pymc-devs/pymc3/wiki/Installation-Guide-(Windows)

          我浪费了几个小时试图修复已经存在的安装。这些练习值得自己拥有一个全新的虚拟环境。

          简而言之:

          1. ⚠ 不要在没有先用 conda 安装依赖项的情况下进行 pip install。 ⚠

          2. 一步创建一个全新的环境(在您的 Anaconda 提示中)。我用过:

          "conda create -n pm3env -c conda-forge "python=3.8" libpython mkl-service m2w64-toolchain numba python-graphviz scipy"

          1. 激活您的新环境:

          “conda 激活 pm3env”

          1. 之后,可以通过以下方式安装 PyMC3:

          “pip install pymc3”(在这里您可以使用 pip - 这又在您的 Anaconda 提示中)

          1. 最后一部分,卸载theano 从上面的消息中可以看出,我已经得到的它是不兼容的。 “康达删除 theano” 和 “conda install -c conda-forge theano-pymc”

          你准备好了!

          1. 请注意,我没有安装上述 url 中所述的附加依赖项。 如您所见,它没有完全没有错误地导入 theano 和 PyMC3。

          【讨论】:

            猜你喜欢
            • 2021-05-09
            • 2021-10-30
            • 2021-05-22
            • 2021-05-17
            • 2021-07-06
            • 2021-06-14
            • 2021-06-05
            • 2022-01-18
            • 2018-12-31
            相关资源
            最近更新 更多