Sean Xu
Sean Xu

Reputation: 33

sklearn "numpy.dtype has the wrong size, try recompiling" in both pycharm and terminal

I got "numpy.dtype has the wrong size, try recompiling" in both pycharm and terminal when compiling Sci-kit learning. I've upgraded all packages(numpy, scikit to the latest), nothing works.Python version is 2.7. Please help. Appreciate!

    checking for nltk
    Traceback (most recent call last):
    File "startup.py", line 6, in <module>
    import nltk
      File "/Library/Python/2.7/site-packages/nltk/__init__.py", line 128, in <module>
      from nltk.chunk import *
      File "/Library/Python/2.7/site-packages/nltk/chunk/__init__.py", line 157, in <module>
   from nltk.chunk.api import ChunkParserI
  File "/Library/Python/2.7/site-packages/nltk/chunk/api.py", line 13, in <module>
    from nltk.parse import ParserI
  File "/Library/Python/2.7/site-packages/nltk/parse/__init__.py", line 79, in <module>
    from nltk.parse.transitionparser import TransitionParser
  File "/Library/Python/2.7/site-packages/nltk/parse/transitionparser.py", line 21, in <module>
    from sklearn.datasets import load_svmlight_file
  File "/Library/Python/2.7/site-packages/sklearn/__init__.py", line 57, in <module>
    from .base import clone
  File "/Library/Python/2.7/site-packages/sklearn/base.py", line 11, in <module>
    from .utils.fixes import signature
  File "/Library/Python/2.7/site-packages/sklearn/utils/__init__.py", line 10, in <module>
    from .murmurhash import murmurhash3_32
  File "numpy.pxd", line 155, in init sklearn.utils.murmurhash (sklearn/utils/murmurhash.c:5029)
ValueError: numpy.dtype has the wrong size, try recompiling

Upvotes: 3

Views: 3154

Answers (2)

Prayson W. Daniel
Prayson W. Daniel

Reputation: 15606

The problem occurs when you are using incompatible versions. Check the versions using:

pip freeze

or, for a specific module

pip freeze | grep Module_Name

I fix my problem by updating all packages:

pip install -U scikit-learn numpy scipy pandas matplotlib

As of Today(30/11/2016). These versions are compatible:

matplotlib==1.5.2
nltk==3.2.1
numpy==1.11.2
pandas==0.19.1
scikit-learn==0.18.1
scipy==0.18.1
textblob==0.11.1

Upvotes: 0

Matthew Brett
Matthew Brett

Reputation: 925

The error "numpy.dtype has the wrong size, try recompiling" means that sklearn was compiled against a numpy more recent than the numpy version sklearn is now trying to import. To fix this, you need to make sure that sklearn is compiled against the version of numpy that it is now importing, or an earlier version. See ValueError: numpy.dtype has the wrong size, try recompiling for a detailed explanation.

I guess from your paths that you are using the OSX system Python (the one that ships with OSX, at /usr/bin/python). Apple has modified this Python in a way that makes it pick up its own version of numpy rather than any version that you install with pip etc - see https://github.com/MacPython/wiki/wiki/Which-Python#system-python-and-extra-python-packages . I strongly recommend you switch to Python.org or homebrew Python to make it easier to work with packages depending on numpy.

Upvotes: 1

Related Questions