从pyxdameraulevenshtein导入会出现以下错误

pyxdameraulevenshtein==1.5.3
pandas==1.1.4
scikit-learn==0.20.2. 

Numpy是1.16.1。

在Python 3.6中工作良好,在Python 3.7中问题。

有人在使用Python 3.7(3.7.9)时遇到过类似的问题吗?

from pyxdameraulevenshtein import normalized_damerau_levenshtein_distance as norm_dl_dist
__init__.pxd:242: in init pyxdameraulevenshtein
    ???
E   ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

当前回答

不升级numpy的解决方案

虽然升级numpy版本通常可以解决这个问题,但并不总是可行的。一个很好的例子是,当你使用tensorflow==2.6.0时,它与最新的numpy版本不兼容(它需要~=1.19.2)。

正如在FZeiser的回答中已经提到的,在1.20.0版本中numpys C API发生了变化。有一些包在构建时依赖于这个C API,例如pyxdameraulevenshtein。鉴于pips依赖解析器不保证安装包的任何顺序,可能会发生以下情况:

pip figures out that it needs to install numpy and it chooses the latest version, 1.21.2 as of the time writing this answer. It then builds a package that depends on numpy and its C API, e.g. pyxdameraulevenshtein. This package is now compatible with numpy 1.21.2 C API. At a later point pip needs to install a package that has a requirement for an older version of numpy, e.g. tensorflow==2.6.0 which would try to install numpy==1.19.5. As a result, numpy==1.21.2 is uninstalled and the older version is installed. When running code that uses pyxdameraulevenshtein, its current installation relies on the updated numpy C API, yet the numpy version was downgraded which would result in the error.

解决方案

您应该使用过时的numpy C API重新构建包,以确保它与当前安装的numpy版本兼容。例如,对于pyxdameraulevenshtein:

pip uninstall pyxdameraulevenshtein
pip install pyxdameraulevenshtein --no-binary pyxdameraulevenshtein

其他回答

Numpy 1.22版本为我解决了这个问题。

对于任何使用诗歌的人来说,有必要进行实验。对于numpy<1.20依赖项的应用程序,New-installer设置为true才能正确构建,即:

poetry config experimental.new-installer true

默认情况下是正确的,但如果它被改变了(就像我的情况一样),它会让你识破。

我的应用程序使用Tensorflow,因此我没有升级到>1.20的选项。诗歌也不支持无二进制依赖。

这是一个更详细的版本的[SO]: ValueError: numpy。Ndarray大小改变,可能表示二进制不兼容。预期从C头得到88,从PyObject得到80 (@FZeiser的回答)(很棒的回答)。

简而言之,这是一个ABI变化(在NumPy中)。 因此,在任何情况下,2个版本(包含或不包含更改)都不应该混合在一起。 错误消息(对某些用户具有误导性)来自PyxDamerauLevenshtein。

1. NumPy

[NumPy]: NumPy 1.20.0 Release Notes - np的大小。Ndarray和np。Void_改变状态:

The size of the PyArrayObject and PyVoidScalarObject structures have changed. The following header definition has been removed: #define NPY_SIZEOF_PYARRAYOBJECT (sizeof(PyArrayObject_fields)) since the size must not be considered a compile time constant: it will change for different runtime versions of NumPy. The most likely relevant use are potential subclasses written in C which will have to be recompiled and should be updated. Please see the documentation for PyArrayObject for more details and contact the NumPy developers if you are affected by this change. NumPy will attempt to give a graceful error but a program expecting a fixed structure size may have undefined behaviour and likely crash.

[GitHub]: numpy/numpy – (v1.19.5) numpy/numpy/core/include/numpy/ndarraytypes.h#726:

#define NPY_SIZEOF_PYARRAYOBJECT (sizeof(PyArrayObject_fields))

是最后一个具有它的,在从v1.20.0开始的后续版本(及其之前的rc)中,该行将被注释掉。 这里值得一提的是,在相同的版本之间,一个新成员被添加到PyArrayObject_fields结构(大约20行以上):

void *_buffer_info;  /* private buffer info, tagged to allow warning */

错误消息中的数字(80和88)开始有了一些意义。

(上面的)两个版本之间有一个界限:任何用一个版本构建,用另一个版本运行的场景都是不受支持的。这就像滥用任何其他库一样:使用(headers和.so (.lib) from)一个版本构建,而使用(. so (.dll) from)另一个版本运行——当这两个版本API / ABI不兼容时。

出现2例:

构建>=v1.20.0,运行<=v1.19.5:不支持 构建<=v1.19.5,运行>=v1.20.0:技术上也不支持,但由于在编译(预处理)时间没有更多的值计算([SO]: LNK2005错误在CLR Windows窗体(@CristiFati的答案)),它将工作

[GitHub]: numpy/numpy - ENH,API:在数组上存储导出的缓冲区信息(1)是引入更改的提交。

2. PyxDamerauLevenshtein

[GitHub]: lanl/pyxDamerauLevenshtein - pyxDamerauLevenshtein是一个依赖NumPy的扩展模块(C + Cython)。源代码(间接地)包含ndarraytypes.h。

浏览[PyPI]: pyxDamerauLevenshtein(至少是最新版本),只有一个二进制:OSX pc064和一个Python版本(可能是包发布时的LTS)。因此,在所有其他平台上安装pip时,它都是从源代码构建的。

为简单起见,将使用v1.5.3(如问题中所示)。 作为旁注,虽然setup.py需要NumPy >=v1.16.1,但有一个requirements.txt文件包含v1.16.1作为依赖项(这有点误导-特别是在浅显地研究时)。

错误消息是在v1.5.1中添加的(专门针对这个NumPy ABI更改),然后在v1.7.0中试图在构建时摆脱对NumPy的依赖时将其删除。我想这是因为经常遇到这种情况所产生的噩梦(其他包取决于特定的NumPy版本)。 删除提交:[GitHub]: lanl/pyxDamerauLevenshtein -第一次尝试远离NumPy。

3.例子

一旦理论被搞清楚了,重现这个问题就不难了。 步骤:

安装NumPy <=v1.19.5 安装PyxDamerauLevenshtein v1.5.3

我在Win上准备了我的“演示”,因为它恰好是我目前启动的操作系统。 还有一些额外的命令用于捕获过程中的状态(在几个点上)。还有一些(不重要的)输出将被剥离:

(py_pc064_03.07_test1_q066060487) [cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q066060487]> :: Python 3.7 console (py_pc064_03.07_test1_q066060487) [cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q066060487]> sopr.bat ### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ### [prompt]> [prompt]> python -c "import sys;print(\"\n\".join((sys.executable, sys.version)))" E:\Work\Dev\VEnvs\py_pc064_03.07_test1_q066060487\Scripts\python.exe 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)] [prompt]> [prompt]> python -m pip freeze [prompt]> [prompt]> python -m pip install numpy==1.19.5 Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com Collecting numpy==1.19.5 Downloading numpy-1.19.5-cp37-cp37m-win_amd64.whl (13.2 MB) ---------------------------------------- 13.2/13.2 MB 8.5 MB/s eta 0:00:00 Installing collected packages: numpy Successfully installed numpy-1.19.5 [prompt]> [prompt]> python -m pip freeze numpy==1.19.5 [prompt]> [prompt]> :: Pass -v to see what is actually going on. I`ll truncate some output [prompt]> [prompt]> python -m pip install -v pyxdameraulevenshtein==1.5.3 Using pip 22.3.1 from E:\Work\Dev\VEnvs\py_pc064_03.07_test1_q066060487\lib\site-packages\pip (python 3.7) Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com Collecting pyxdameraulevenshtein==1.5.3 Downloading pyxDamerauLevenshtein-1.5.3.tar.gz (58 kB) ---------------------------------------- 58.5/58.5 kB 1.0 MB/s eta 0:00:00 Running command pip subprocess to install build dependencies Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com, https://pypi.ngc.nvidia.com Collecting setuptools>=40.8.0 Downloading setuptools-66.0.0-py3-none-any.whl (1.3 MB) ---------------------------------------- 1.3/1.3 MB 5.0 MB/s eta 0:00:00 Collecting wheel>=0.33.1 Downloading wheel-0.38.4-py3-none-any.whl (36 kB) Collecting numpy>=1.16.1 Downloading numpy-1.21.6-cp37-cp37m-win_amd64.whl (14.0 MB) ---------------------------------------- 14.0/14.0 MB 9.2 MB/s eta 0:00:00 Installing collected packages: wheel, setuptools, numpy # @TODO - cfati: !!! Check NumPy version used at build time !!! Successfully installed numpy-1.21.6 setuptools-66.0.0 wheel-0.38.4 Installing build dependencies ... done Running command Getting requirements to build wheel running egg_info # @TODO - cfati: Truncated output Preparing metadata (pyproject.toml) ... done Requirement already satisfied: numpy>=1.16.1 in e:\work\dev\venvs\py_pc064_03.07_test1_q066060487\lib\site-packages (from pyxdameraulevenshtein==1.5.3) (1.19.5) Building wheels for collected packages: pyxdameraulevenshtein Running command Building wheel for pyxdameraulevenshtein (pyproject.toml) running bdist_wheel running build running build_ext building 'pyxdameraulevenshtein' extension creating build creating build\temp.win-amd64-cpython-37 creating build\temp.win-amd64-cpython-37\Release creating build\temp.win-amd64-cpython-37\Release\pyxdameraulevenshtein C:\Install\pc064\Microsoft\VisualStudioCommunity\2022\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe /c /nologo /O2 /W3 /GL /DNDEBUG /MD -IC:\Users\cfati\AppData\Local\Temp\pip-build-env-o_18jg2s\overlay\Lib\site-packages\numpy\core\include -IE:\Work\Dev\VEnvs\py_pc064_03.07_test1_q066060487\include -Ic:\Install\pc064\Python\Python\03.07\include -Ic:\Install\pc064\Python\Python\03.07\Include -IC:\Install\pc064\Microsoft\VisualStudioCommunity\2022\VC\Tools\MSVC\14.34.31933\include -IC:\Install\pc064\Microsoft\VisualStudioCommunity\2022\VC\Tools\MSVC\14.34.31933\ATLMFC\include -IC:\Install\pc064\Microsoft\VisualStudioCommunity\2022\VC\Auxiliary\VS\include "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\cppwinrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" /Tcpyxdameraulevenshtein/pyxdameraulevenshtein.c /Fobuild\temp.win-amd64-cpython-37\Release\pyxdameraulevenshtein/pyxdameraulevenshtein.obj pyxdameraulevenshtein.c C:\Users\cfati\AppData\Local\Temp\pip-build-env-o_18jg2s\overlay\Lib\site-packages\numpy\core\include\numpy\npy_1_7_deprecated_api.h(14) : Warning Msg: Using deprecated NumPy API, disable it with #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION pyxdameraulevenshtein/pyxdameraulevenshtein.c(2240): warning C4244: '=': conversion from 'Py_ssize_t' to 'unsigned long', possible loss of data pyxdameraulevenshtein/pyxdameraulevenshtein.c(2271): warning C4244: '=': conversion from 'Py_ssize_t' to 'unsigned long', possible loss of data pyxdameraulevenshtein/pyxdameraulevenshtein.c(2358): warning C4244: '=': conversion from 'Py_ssize_t' to 'unsigned long', possible loss of data pyxdameraulevenshtein/pyxdameraulevenshtein.c(2434): warning C4244: '=': conversion from 'Py_ssize_t' to 'unsigned long', possible loss of data pyxdameraulevenshtein/pyxdameraulevenshtein.c(2957): warning C4244: '=': conversion from 'double' to 'float', possible loss of data creating C:\Users\cfati\AppData\Local\Temp\pip-install-t79ijgrr\pyxdameraulevenshtein_4dee1beb9a9542bb89a45fc96b191728\build\lib.win-amd64-cpython-37 C:\Install\pc064\Microsoft\VisualStudioCommunity\2022\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:E:\Work\Dev\VEnvs\py_pc064_03.07_test1_q066060487\libs /LIBPATH:c:\Install\pc064\Python\Python\03.07\libs /LIBPATH:c:\Install\pc064\Python\Python\03.07 /LIBPATH:E:\Work\Dev\VEnvs\py_pc064_03.07_test1_q066060487\PCbuild\amd64 /LIBPATH:C:\Install\pc064\Microsoft\VisualStudioCommunity\2022\VC\Tools\MSVC\14.34.31933\ATLMFC\lib\x64 /LIBPATH:C:\Install\pc064\Microsoft\VisualStudioCommunity\2022\VC\Tools\MSVC\14.34.31933\lib\x64 "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.22000.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\\lib\10.0.22000.0\\um\x64" /EXPORT:PyInit_pyxdameraulevenshtein build\temp.win-amd64-cpython-37\Release\pyxdameraulevenshtein/pyxdameraulevenshtein.obj /OUT:build\lib.win-amd64-cpython-37\pyxdameraulevenshtein.cp37 -win_amd64.pyd /IMPLIB:build\temp.win-amd64-cpython-37\Release\pyxdameraulevenshtein\pyxdameraulevenshtein.cp37-win_amd64.lib Creating library build\temp.win-amd64-cpython-37\Release\pyxdameraulevenshtein\pyxdameraulevenshtein.cp37-win_amd64.lib and object build\temp.win-amd64-cpython-37\Release\pyxdameraulevenshtein\pyxdameraulevenshtein.cp37-win_amd64.exp Generating code Finished generating code installing to build\bdist.win-amd64\wheel # @TODO - cfati: Truncated output running install_scripts creating build\bdist.win-amd64\wheel\pyxDamerauLevenshtein-1.5.3.dist-info\WHEEL creating 'C:\Users\cfati\AppData\Local\Temp\pip-wheel-g6cfcj3b\.tmp-n2i1vw8v\pyxDamerauLevenshtein-1.5.3-cp37-cp37m-win_amd64.whl' and adding 'build\bdist.win-amd64\wheel' to it adding 'pyxdameraulevenshtein.cp37-win_amd64.pyd' adding 'pyxDamerauLevenshtein-1.5.3.dist-info/METADATA' adding 'pyxDamerauLevenshtein-1.5.3.dist-info/WHEEL' adding 'pyxDamerauLevenshtein-1.5.3.dist-info/top_level.txt' adding 'pyxDamerauLevenshtein-1.5.3.dist-info/RECORD' removing build\bdist.win-amd64\wheel C:\Users\cfati\AppData\Local\Temp\pip-build-env-o_18jg2s\overlay\Lib\site-packages\wheel\bdist_wheel.py:83: RuntimeWarning: Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect if get_flag("Py_DEBUG", hasattr(sys, "gettotalrefcount"), warn=(impl == "cp")): C:\Users\cfati\AppData\Local\Temp\pip-build-env-o_18jg2s\overlay\Lib\site-packages\wheel\bdist_wheel.py:89: RuntimeWarning: Config variable 'WITH_PYMALLOC' is unset, Python ABI tag may be incorrect warn=(impl == "cp" and sys.version_info < (3, 8)), Building wheel for pyxdameraulevenshtein (pyproject.toml) ... done Created wheel for pyxdameraulevenshtein: filename=pyxDamerauLevenshtein-1.5.3-cp37-cp37m-win_amd64.whl size=24372 sha256=ced6c506896c3b1d98f8ddd165b4bf8a399287fd9f5543f2398953b479173e86 Stored in directory: C:\Users\cfati\AppData\Local\Temp\pip-ephem-wheel-cache-6epkbo0t\wheels\b4\f5\9e\39cf91e589064ceb8a4db3b6d9b2c7f267af79f9542f2ddbb3 Successfully built pyxdameraulevenshtein Installing collected packages: pyxdameraulevenshtein Successfully installed pyxdameraulevenshtein-1.5.3 [prompt]> [prompt]> :: Existing NumPy version (used at runtime) [prompt]> python -m pip freeze numpy==1.19.5 pyxDamerauLevenshtein==1.5.3 [prompt]> [prompt]> python -c "from pyxdameraulevenshtein import normalized_damerau_levenshtein_distance;print(\"Done.\")" Traceback (most recent call last): File "<string>", line 1, in <module> File "__init__.pxd", line 242, in init pyxdameraulevenshtein ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject [prompt]> [prompt]> python -m pip install numpy==1.20.0 Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com Collecting numpy==1.20.0 Downloading numpy-1.20.0-cp37-cp37m-win_amd64.whl (13.6 MB) ---------------------------------------- 13.6/13.6 MB 7.0 MB/s eta 0:00:00 Installing collected packages: numpy Attempting uninstall: numpy Found existing installation: numpy 1.19.5 Uninstalling numpy-1.19.5: Successfully uninstalled numpy-1.19.5 Successfully installed numpy-1.20.0 [prompt]> [prompt]> python -m pip freeze numpy==1.20.0 pyxDamerauLevenshtein==1.5.3 [prompt]> [prompt]> python -c "from pyxdameraulevenshtein import normalized_damerau_levenshtein_distance;print(\"Done.\")" Done.

原因很明显(尽管隐藏在详细的输出中):在构建PyxDamerauLevenshtein时,PIP(默默地和临时地)下载(并用于构建)NumPy v1.21.6(在本例中),忽略现有的安装版本。然后,在运行时使用v1.19.5,因此出现错误。

注意:该问题在最新的PyxDamerauLevenshtein版本(回答时为v1.7.1)中不再重现。

4. 一个转折

正如问题中所提到的,这些东西似乎适用于Python 3.6。

一开始我认为这部分的提交(#1)是罪魁祸首:

+     if (_buffer_info_free(fa->_buffer_info, (PyObject *)self) < 0) {
+         PyErr_WriteUnraisable(NULL);
+     }

[Python.3.7。PyErr_WriteUnraisable(PyObject *obj)的状态(v3.7,但不适用于v3.6):

调用此函数时必须设置异常。

从那里,在[GitHub]: python/cpython - (v3.7.0) cpython/ python/ errors.c#206中,PyErr_GivenExceptionMatches似乎比v3.6.15更严格,这就是为什么在传递NULL时没有引发异常的原因。

但我错了,事情其实简单得多:

(py_pc064_03.06_test1_q066060487) [cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q066060487]> :: Python 3.6 console (py_pc064_03.06_test1_q066060487) [cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q066060487]> sopr.bat ### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ### [prompt]> [prompt]> python -c "import sys;print(\"\n\".join((sys.executable, sys.version)))" e:\Work\Dev\VEnvs\py_pc064_03.06_test1_q066060487\Scripts\python.exe 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] [prompt]> [prompt]> python -m pip freeze [prompt]> [prompt]> python -m pip install numpy==1.19.5 Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com Collecting numpy==1.19.5 Downloading numpy-1.19.5-cp36-cp36m-win_amd64.whl (13.2 MB) |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 13.2 MB 1.6 MB/s Installing collected packages: numpy Successfully installed numpy-1.19.5 [prompt]> [prompt]> python -m pip freeze numpy==1.19.5 [prompt]> [prompt]> :: Pass -v (again) to see what is actually going on. I`ll truncate some output [prompt]> [prompt]> python -m pip install -v pyxdameraulevenshtein==1.5.3 Using pip 21.3.1 from e:\Work\Dev\VEnvs\py_pc064_03.06_test1_q066060487\lib\site-packages\pip (python 3.6) Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com Collecting pyxdameraulevenshtein==1.5.3 Downloading pyxDamerauLevenshtein-1.5.3.tar.gz (58 kB) |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 58 kB 1.6 MB/s Running command 'e:\Work\Dev\VEnvs\py_pc064_03.06_test1_q066060487\Scripts\python.exe' 'e:\Work\Dev\VEnvs\py_pc064_03.06_test1_q066060487\lib\site-packages\pip' install --ignore-installed --no-user --prefix 'C:\Users\cfati\AppData\Local\Temp\pip-build-env-h6hif14f\overlay' --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple --extra-index-url https://pypi.ngc.nvidia.com --trusted-host pypi.ngc.nvidia.com -- 'setuptools>=40.8.0' 'wheel>=0.33.1' 'numpy>=1.16.1' Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com, https://pypi.ngc.nvidia.com Collecting setuptools>=40.8.0 Downloading setuptools-59.6.0-py3-none-any.whl (952 kB) Collecting wheel>=0.33.1 Downloading wheel-0.37.1-py2.py3-none-any.whl (35 kB) Collecting numpy>=1.16.1 Downloading numpy-1.19.5-cp36-cp36m-win_amd64.whl (13.2 MB) Installing collected packages: wheel, setuptools, numpy Successfully installed numpy-1.19.5 setuptools-59.6.0 wheel-0.37.1 Installing build dependencies ... done Running command 'e:\Work\Dev\VEnvs\py_pc064_03.06_test1_q066060487\Scripts\python.exe' 'e:\Work\Dev\VEnvs\py_pc064_03.06_test1_q066060487\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py' get_requires_for_build_wheel 'C:\Users\cfati\AppData\Local\Temp\tmpfdchqls9' running egg_info # @TODO - cfati: Truncated output Preparing metadata (pyproject.toml) ... done Requirement already satisfied: numpy>=1.16.1 in e:\work\dev\venvs\py_pc064_03.06_test1_q066060487\lib\site-packages (from pyxdameraulevenshtein==1.5.3) (1.19.5) Building wheels for collected packages: pyxdameraulevenshtein Running command 'e:\Work\Dev\VEnvs\py_pc064_03.06_test1_q066060487\Scripts\python.exe' 'e:\Work\Dev\VEnvs\py_pc064_03.06_test1_q066060487\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py' build_wheel 'C:\Users\cfati\AppData\Local\Temp\tmp0_edf2js' running bdist_wheel running build running build_ext building 'pyxdameraulevenshtein' extension creating build creating build\temp.win-amd64-3.6 creating build\temp.win-amd64-3.6\Release creating build\temp.win-amd64-3.6\Release\pyxdameraulevenshtein C:\Install\pc064\Microsoft\VisualStudioCommunity\2022\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\cfati\AppData\Local\Temp\pip-build-env-h6hif14f\overlay\Lib\site-packages\numpy\core\include -Ic:\Install\pc064\Python\Python\03.06.08\include -Ic:\Install\pc064\Python\Python\03.06.08\include -IC:\Install\pc064\Microsoft\VisualStudioCommunity\2022\VC\Tools\MSVC\14.34.31933\include -IC:\Install\pc064\Microsoft\VisualStudioCommunity\2022\VC\Tools\MSVC\14.34.31933\ATLMFC\include -IC:\Install\pc064\Microsoft\VisualStudioCommunity\2022\VC\Auxiliary\VS\include "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.22000.0\\cppwinrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\in clude\um" /Tcpyxdameraulevenshtein/pyxdameraulevenshtein.c /Fobuild\temp.win-amd64-3.6\Release\pyxdameraulevenshtein/pyxdameraulevenshtein.obj pyxdameraulevenshtein.c C:\Users\cfati\AppData\Local\Temp\pip-build-env-h6hif14f\overlay\Lib\site-packages\numpy\core\include\numpy\npy_1_7_deprecated_api.h(14) : Warning Msg: Using deprecated NumPy API, disable it with #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION pyxdameraulevenshtein/pyxdameraulevenshtein.c(2240): warning C4244: '=': conversion from 'Py_ssize_t' to 'unsigned long', possible loss of data pyxdameraulevenshtein/pyxdameraulevenshtein.c(2271): warning C4244: '=': conversion from 'Py_ssize_t' to 'unsigned long', possible loss of data pyxdameraulevenshtein/pyxdameraulevenshtein.c(2358): warning C4244: '=': conversion from 'Py_ssize_t' to 'unsigned long', possible loss of data pyxdameraulevenshtein/pyxdameraulevenshtein.c(2434): warning C4244: '=': conversion from 'Py_ssize_t' to 'unsigned long', possible loss of data pyxdameraulevenshtein/pyxdameraulevenshtein.c(2957): warning C4244: '=': conversion from 'double' to 'float', possible loss of data creating C:\Users\cfati\AppData\Local\Temp\pip-install-jbo5i6wm\pyxdameraulevenshtein_f0a231227bfc404898102cc0b821c01c\build\lib.win-amd64-3.6 C:\Install\pc064\Microsoft\VisualStudioCommunity\2022\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:c:\Install\pc064\Python\Python\03.06.08\Libs /LIBPATH:e:\Work\Dev\VEnvs\py_pc064_03.06_test1_q066060487\libs /LIBPATH:e:\Work\Dev\VEnvs\py_pc064_03.06_test1_q066060487\PCbuild\amd64 /LIBPATH:C:\Install\pc064\Microsoft\VisualStudioCommunity\2022\VC\Tools\MSVC\14.34.31933\ATLMFC\lib\x64 /LIBPATH:C:\Install\pc064\Microsoft\VisualStudioCommunity\2022\VC\Tools\MSVC\14.34.31933\lib\x64 "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.22000.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\\lib\10.0.22000.0\\um\x64" /EXPORT:PyInit_pyxdameraulevenshtein build\temp.win-amd64-3.6\Release\pyxdameraulevenshtein/pyxdameraulevenshtein.obj /OUT:build\lib.win-amd64-3.6\pyxdameraulevenshtein.cp36-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.6\Release\p yxdameraulevenshtein\pyxdameraulevenshtein.cp36-win_amd64.lib Creating library build\temp.win-amd64-3.6\Release\pyxdameraulevenshtein\pyxdameraulevenshtein.cp36-win_amd64.lib and object build\temp.win-amd64-3.6\Release\pyxdameraulevenshtein\pyxdameraulevenshtein.cp36-win_amd64.exp Generating code Finished generating code installing to build\bdist.win-amd64\wheel # @TODO - cfati: Truncated output running install_scripts creating build\bdist.win-amd64\wheel\pyxDamerauLevenshtein-1.5.3.dist-info\WHEEL creating 'C:\Users\cfati\AppData\Local\Temp\pip-wheel-wpe1zd_h\tmpdhak06i5\pyxDamerauLevenshtein-1.5.3-cp36-cp36m-win_amd64.whl' and adding 'build\bdist.win-amd64\wheel' to it adding 'pyxdameraulevenshtein.cp36-win_amd64.pyd' adding 'pyxDamerauLevenshtein-1.5.3.dist-info/METADATA' adding 'pyxDamerauLevenshtein-1.5.3.dist-info/WHEEL' adding 'pyxDamerauLevenshtein-1.5.3.dist-info/top_level.txt' adding 'pyxDamerauLevenshtein-1.5.3.dist-info/RECORD' removing build\bdist.win-amd64\wheel C:\Users\cfati\AppData\Local\Temp\pip-build-env-h6hif14f\overlay\Lib\site-packages\wheel\bdist_wheel.py:82: RuntimeWarning: Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect warn=(impl == 'cp')): C:\Users\cfati\AppData\Local\Temp\pip-build-env-h6hif14f\overlay\Lib\site-packages\wheel\bdist_wheel.py:87: RuntimeWarning: Config variable 'WITH_PYMALLOC' is unset, Python ABI tag may be incorrect sys.version_info < (3, 8))) \ Building wheel for pyxdameraulevenshtein (pyproject.toml) ... done Created wheel for pyxdameraulevenshtein: filename=pyxDamerauLevenshtein-1.5.3-cp36-cp36m-win_amd64.whl size=27385 sha256=e17febb7db9cbe5e7726c486367b189bbd8b07d93c845ab580ee69f652eed002 Stored in directory: C:\Users\cfati\AppData\Local\Temp\pip-ephem-wheel-cache-g6lraow9\wheels\ab\e3\f3\34dfd385a44f053693d576e00ea4a6f4beb73366f7237271cf Successfully built pyxdameraulevenshtein Installing collected packages: pyxdameraulevenshtein Successfully installed pyxdameraulevenshtein-1.5.3 Link requires a different Python (3.6.8 not in: '>=3.7'): https://files.pythonhosted.org/packages/9f/8b/a094f5da22d7abf5098205367b3296dd15b914f4232af5ca39ba6214d08c/pip-22.0-py3-none-any.whl#sha256=6cb1ea2bd7fda0668e26ae8c3e45188f301a7ef17ff22efe1f70f3643e56a822 (from https://pypi.org/simple/pip/) (requires-python:>=3.7) # @TODO - cfati: Truncated output [prompt]> [prompt]> python -m pip freeze numpy==1.19.5 pyxDamerauLevenshtein==1.5.3 [prompt]> [prompt]> python -c "from pyxdameraulevenshtein import normalized_damerau_levenshtein_distance;print(\"Done.\")" Done.

因此,在Python 3.6上,不会遇到这种情况,因为最新(构建的)NumPy版本是v1.19.5。

5. 结论

我故意在这个(简化的)场景(MCVE)中运行,以证明一个观点。 普通用户在安装依赖于旧NumPy版本的包时通常会遇到这种情况。但是由于更新的包版本(带有更新的依赖版本)不断出现,因此随着时间的推移,遇到它的机会逐渐消失。

然而,如果有人遇到了这个问题,这里有一堆(通用的)指导方针来克服它:

在安装PyxDamerauLevenshtein之前安装(upgrade) NumPy >=v1.20.0(最好)(或者更好:不再使用旧版本) 安装PyxDamerauLevenshtein >=v1.7.0 指导PIP ([PyPA。PIP安装)不升级依赖项 “手动”构建PyxDamerauLevenshtein (python setup.py Build),在这种情况下,我注意到使用了现有的NumPy版本(这是人们所期望的(并且没有使用PIP))

请注意,这可能也适用于其他包,并且可能涉及其他限制 总而言之 检查: 在安装所有必需的包之后(可能会将NumPy降级到<=v1.19.5) 不断地(如果包安装是一个连续的过程) NumPy版本(pythnon -m pip freeze),如果是这样,升级它(python -m pip upgrade NumPy)

相关的(或多或少):

如何修复pythonnet安装过程中的错误(@CristiFati的回答) [SO]:无法使用pip安装pyo (@CristiFati的回答) [SO]:如何在Windows 10上安装特定Python版本的包?(@CristiFati回答) [SO]: PyWin32和Python 3.8.0 (@CristiFati的答案)

在你安装任何包之后,确保你重新启动内核并且应该工作。通常包会自动升级,你所需要的只是快速重启。至少,这在我的情况下工作,当我试图安装和使用石榴时,我得到了同样的错误。

我在python3.10.4,numpy1.21.5中遇到了同样的问题,我只有在通过pip卸载numpy和pip安装numpy将numpy更新到1.22.3后才解决了这个问题。只有pip install -upgrade numpy没有工作。

PS D:\quant\vnpy-master\examples\veighna_trader> python .\run.py Traceback (most recent call last): File "D:\quant\vnpy-master\examples\veighna_trader\run.py", line 31, in from vnpy_optionmaster import OptionMasterApp File "D:\it_soft\python3.10.4\Lib\site-packages\vnpy_optionmaster__init__.py", line 26, in from .engine import OptionEngine, APP_NAME File "D:\it_soft\python3.10.4\Lib\site-packages\vnpy_optionmaster\engine.py", line 34, in from .pricing import binomial_tree_cython as binomial_tree File "binomial_tree_cython.pyx", line 1, in init binomial_tree_cython ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject