development

ValueError : numpy.dtype의 크기가 잘못되었습니다. 다시 컴파일 해보세요.

big-blog 2020. 9. 16. 08:07
반응형

ValueError : numpy.dtype의 크기가 잘못되었습니다. 다시 컴파일 해보세요.


방금 python 2.7에 pandas와 statsmodels 패키지를 설치했습니다. "pd로 pandas 가져 오기"를 시도했을 때이 오류 메시지가 나옵니다. 누구든지 도울 수 있습니까? 감사!!!

numpy.dtype has the wrong size, try recompiling
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\analytics\ext\python27\lib\site-packages\statsmodels-0.5.0-py2.7-win32.egg\statsmodels\formula\__init__.py",
line 4, in <module>
    from formulatools import handle_formula_data
  File "C:\analytics\ext\python27\lib\site-packages\statsmodels-0.5.0-py2.7-win32.egg\statsmodels\formula\formulatools.p
y", line 1, in <module>
    import statsmodels.tools.data as data_util
  File "C:\analytics\ext\python27\lib\site-packages\statsmodels-0.5.0-py2.7-win32.egg\statsmodels\tools\__init__.py", li
ne 1, in <module>
    from tools import add_constant, categorical
  File "C:\analytics\ext\python27\lib\site-packages\statsmodels-0.5.0-py2.7-win32.egg\statsmodels\tools\tools.py", line
14, in <module>
    from pandas import DataFrame
  File "C:\analytics\ext\python27\lib\site-packages\pandas\__init__.py", line 6, in <module>
    from . import hashtable, tslib, lib
  File "numpy.pxd", line 157, in init pandas.tslib (pandas\tslib.c:49133)
ValueError: numpy.dtype has the wrong size, try recompiling

(내 의견에 대해 조금 확장)

Numpy 개발자는 일반적으로 이전 버전과 호환되는 바이너리 인터페이스 (ABI)를 유지하는 정책을 따릅니다. 그러나 ABI는 앞으로 호환되지 않습니다.

의미 :

컴파일 된 확장에서 numpy를 사용하는 패키지는 특정 버전의 numpy에 대해 컴파일됩니다. numpy의 향후 버전은 패키지의 컴파일 된 확장과 호환됩니다 (예외 사항은 아래 참조). 이러한 다른 패키지의 배포자는 최신 버전의 numpy에 대해 패키지를 다시 컴파일 할 필요가 없으며 사용자가 최신 버전의 numpy로 업데이트 할 때 이러한 다른 패키지를 업데이트 할 필요가 없습니다.

그러나 이것은 다른 방향으로 가지 않습니다. 패키지가 특정 numpy 버전 (예 : 1.7)에 대해 컴파일 된 경우 해당 패키지의 바이너리가 이전 numpy 버전 (예 : 1.6)에서 작동 할 것이라는 보장은 없으며 매우 자주 또는 대부분 그렇지 않습니다.

최신 버전의 numpy에 대해 컴파일 된 pandas 및 statsmodels와 같은 패키지의 바이너리 배포는 이전 버전의 numpy가 설치된 경우 작동하지 않습니다. 예를 들어 matplotlib와 같은 일부 패키지는 올바르게 기억하면 지원하는 가장 오래된 numpy 버전에 대해 확장을 컴파일합니다. 이 경우 동일한 이전 버전 또는 최신 버전의 numpy를 사용하는 사용자는 해당 바이너리를 사용할 수 있습니다.

질문의 오류 메시지는 바이너리 비 호환성의 일반적인 결과입니다.

해결책은 numpy를 최소한 pandas 또는 statsmodels가 컴파일 된 버전으로 업데이트하거나 이미 설치된 numpy의 이전 버전에 대해 pandas 및 statsmodels를 다시 컴파일하여 바이너리 호환 버전을 가져 오는 것입니다.

ABI 이전 버전과의 호환성 깨기 :

때때로 numpy의 개선 또는 리팩토링으로 인해 ABI 이전 버전과의 호환성이 깨집니다. 이것은 numpy 1.4.0에서 (의도하지 않게) 발생했습니다. 결과적으로 numpy를 1.4.0으로 업데이트 한 사용자는 이전 버전의 numpy에 대해 컴파일 된 다른 모든 컴파일 된 패키지와 바이너리 비 호환성을 가졌습니다. 이를 위해서는 numpy를 사용하는 바이너리 확장이있는 모든 패키지를 ABI 비 호환 버전에서 작동하도록 다시 컴파일해야합니다.


나를 위해 (Mac OS X Maverics, Python 2.7)

easy_install --upgrade numpy

도움이되었습니다. 그런 다음 pip를 사용하여 최신 패키지 pandas , scikit-learn 등을 설치할 수 있습니다 .

pip install pandas

나는 그것이 구식이거나 불일치하는 단순한 버전이라는 것을 알았고 다음과 같이 수정되었습니다.

pip install --upgrade numpy
pip install --upgrade scipy
pip install --upgrade pandas

또는 하나의 라이너로 작업 할 수 있습니다.

pip install --upgrade numpy scipy pandas

다른 라이브러리에서 비슷한 오류가 발생했으며 시스템에 여러 버전의 numpy가 설치되어 있음을 깨달았습니다. 나를위한 수정 사항은 내 PYTHONPATH를 편집하고 최신 버전의 numpy가 포함 된 사이트 패키지를 첫 번째 위치에 배치하는 것이 었습니다.


마찬가지로 여기 , 나에 대해서만은 sudo pip install pandas==0.13.1


I also encounter this error when use pandas to access MYSQL. This error message indicates a binary compatible issue and can be resolved by using latest version of pandas and numpy package. Here is my steps to resolve this issue, and it works well on my Ubuntu 12.04:

cd /tmp/
wget https://pypi.python.org/packages/source/p/pandas/pandas-0.12.0.tar.gz
tar xzvf pandas-0.12.0.tar.gz
cd pandas-0.12.0
easy_install --upgrade numpy

In my case, I had installed pandas-0.10.0.win-amd64-py2.7 but was checking to see if a bug had been fixed in a more recent version of pandas. So I did an easy_install -U to force the upgrade, but then got the above error due to some incompatibilities with numpy etc... when I did

import pandas

To fix, I just reinstalled the pandas-0.10.0.win-amd64-py2.7 binary and everything works. I didn't see this answer (suggests to use pip) which may have helped me (though not sure) Install particular version with easy_install

Also this highlights why one should use virtualenv (which I wasn't).


For me (Mac OS X Mavericks) it worked to install the version for python2.6:

sudo port install py26-scikit-learn

then run:

python2.6 myscript.py

The problem I solved on Webfaction was old numpy library(1.5) which was in conflict with my fresh

pip install pandas

installation in .virtualenv.

The problem was solved after I did pip install pandas out of the virtual environment. The idea came from discussion on https://github.com/pydata/pandas/issues/3711, thanks, cpcloud!


I just meet this 'ValueError' issue and have addressed it. Definitely there's something wrong with numpy package.

But when I try to pip install --upgrade numpy it failed, so I uninstall and download the newest numpy.zip file. Then manually uncompress and python setup.py install it.

Luckly, it works!


Like @user333700 said, required versions of libraries may not meet for each other. You get one library as another's dependency. Then without knowing it was already installed as dependency, you need that specific library and you install one version. With such ways dependencies may mess up.

I lived such a case and looked for a solution. Found this: https://stackoverflow.com/a/12975518/1694344

I had two different versions for egg-info file and folder name of numpy:

drwxr-xr-x. 19 root root   4096 Sep 25 15:00 numpy
drwxr-xr-x.  2 root root   4096 Sep 22 11:25 numpy-1.13.1.dist-info
-rw-r--r--.  1 root root   1630 Nov 20  2015 numpy-1.7.1-py2.7.egg-info

I removed them all and reinstalled numpy with pip.


I had a similar issue, and simply re-installing using pip install ... as suggested in previous comments didn't work.

What worked for me was re-installing with the added flag pip install --no-cache-dir ..., seems there was an incompatible numpy version somewhere in the cache.


There are cases where you want to keep a specific NumPy version and the upgrade option mentioned here will not work. An example that occurred to me was the Python distribution preinstalled with ArcGIS. For ArcPy to work in ArcGIS 10.5.1, that distribution needs to be Python 2.7.12 with NumPy 1.9.3 and any other version of NumPy is probably going to cause issues with your ArcPy functionality.

What you can do with this case is try to install a specific, older version of the problematic third-party library that is supposed to be compatible with the older NumPy version that ArcGIS has.

For instance, scikit-learn 0.19.1 would NOT operate with NumPy 1.9.3 and would result in the same error you mentioned. However, scikit-learn 0.15 works fine. You can test different versions to find the one that works. Just mention the version number through pip:

python -m pip install scikit-learn==0.15

참고URL : https://stackoverflow.com/questions/17709641/valueerror-numpy-dtype-has-the-wrong-size-try-recompiling

반응형