25

I'm on a Mac, and I installed numpy and sklearn in that order. Now, I'm faced with these errors that have already been mentioned on SO several times:

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

ValueError: numpy.dtype has the wrong size, try recompiling

ImportError in importing from sklearn: cannot import name check_build

So, I try to remediate this error by uninstalling numpy, and reinstalling a previous version.

1) sudo pip install --upgrade numpy..gives permission error

...OSError: [Errno 1] Operation not permitted: '/tmp/pip-OVY0Vq-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy-1.8.0rc1-py2.7.egg-info'...

2) I tried brew uninstall numpy, but import numpy still works even after a shell restart.

The only thing left I can think of is to manually delete all of the numpy files, which, on a Mac seeem to be found under sudo rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy

....but even that gives me a permission error. what gives?

Community
  • 1
  • 1
makansij
  • 7,473
  • 28
  • 82
  • 156
  • I probably would just remove the files manually and then to avoid errors and potentially damaging your operating system you should install your packages inside a virtual environment. E.g http://docs.python-guide.org/en/latest/dev/virtualenvs/ – reticentroot Aug 28 '16 at 03:23
  • but, are those the correct files to remove? – makansij Aug 28 '16 at 05:11
  • 1
    even with `sudo`.....it won't let me remove them though!! Suggestions?? – makansij Aug 28 '16 at 05:13
  • Sudo chmod 777 the_path_to_file then try rm again.. that should give you read write access to the file – reticentroot Aug 28 '16 at 15:43
  • 1
    Okay, I try `sudo chmod 777 /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy` and I get `chmod: Unable to change file mode on /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy: Operation not permitted`. What gives? – makansij Aug 29 '16 at 07:48
  • Last thing I would try is to use the su command to become a super user. It is the highest privilege level, perhaps then you can rm or chmod.. if this is a mac you might also want to repair your disk permissions using disk utility. The newer operating systems removed that option but you can Google how to do that. – reticentroot Aug 30 '16 at 01:57
  • 1
    Am I the only one who thinks this shouldn't be that difficult!!!?? – makansij Aug 30 '16 at 05:42
  • No you're not the only one. I've never had this problem. I use pip or git exclusively (I don't use brew for python) and I always use a virtualenv. Installing on to your machines copy of python isn't good practice for a number of reasons. Instead of using terminal to remove it try and manually dragging and dropping the installation into the trash can. The os will ask for a password and that should be it. – reticentroot Aug 30 '16 at 13:03
  • Just as a thought your operating system is fighting you hard on this one you may want to rethink how you're going about doing this. It could be that case that if you did remove it, you might damage you'd os in some way. I would locate the file manually, inside whatever container/ version of python you are using. – reticentroot Aug 30 '16 at 13:15
  • Mac OSX has snatched the scepter of root from your fingers through bash. So you physically cannot delete those files no matter how much you want to. Only an operating system reinstall will nuke them, which only an Apple genius can do for you at cost of time and money. Enjoy your golden handcuffs lol. – Eric Leschinski Aug 27 '17 at 00:10
  • Sounds like you have run up against System Intregrity Protection (SIP) which will prevent you from doing changes on certain files and folders. It can be disabled. See https://stackoverflow.com/questions/30768087/restricted-folder-files-in-os-x-el-capitan#32910408 – tgunr Dec 17 '17 at 10:58

7 Answers7

65

I guess you are using MAC OS. I did a workaround to ignore the existing version of numpy (which MAC won't let you uninstall), and install an upgraded version.

Command :

pip install --upgrade --ignore-installed --install-option '--install-data=/usr/local' numpy

Worked fine for me.

Eric Leschinski
  • 123,728
  • 82
  • 382
  • 321
Zubin
  • 655
  • 5
  • 4
13

I also getting this when I try to install pandas in MAC, but following command help me to get work around. Following command will ignore any previously installed version. Not sure it really fix issue behind though, but you can also have a try:

sudo pip install numpy --ignore-installed numpy
Lola Yan
  • 131
  • 1
  • 2
3

To solve this, I did the following: (note that it is not entirely clear to me which of these solved the problem, since I didn't test thoroughly).

1) Installed python at Python.org instead of Mac's stupid version

2) re-installed all of the modules like numpy, scipy, matplotlib, sklearn and ran this:hash -r python according to this source: Symbol not found: __PyCodecInfo_GetIncrementalDecoder, because it doesn't make python use the cached versions of the modules.

3) Then, I realized that I had this issue: https://github.com/scipy/scipy/issues/5093. To solve it, I had to make sure I installed the scipy module using python -m pip install scipy='0.15.0' instead of just pip install scipy='0.15.0', because this solved the issue based on this source: Can't load Python modules installed via pip from site-packages directory.

So, in conclusion it turns out there really is a big different between what is installed by pip, and what is imported when python is executed from the terminal. So, to ensure that you are using the pip to install the modules into a particular python, you can use python -m pip install <package name>.

Community
  • 1
  • 1
makansij
  • 7,473
  • 28
  • 82
  • 156
2

What works for my Mac OS 10.13.6 (High Sierra):

  1. Just keep uninstalling numpy: $sudo -H pip uninstall numpy DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. Uninstalling numpy-1.16.2: Would remove: /Library/Python/2.7/site-packages/numpy-1.16.2.dist-info/* /Library/Python/2.7/site-packages/numpy/* ... Proceed (y/n)? y Successfully uninstalled numpy-1.16.2 $sudo -H pip uninstall numpy DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. Uninstalling numpy-1.14.2: Would remove: /Library/Python/2.7/site-packages/numpy-1.14.2.dist-info/* ... Proceed (y/n)? y Successfully uninstalled numpy-1.14.2

  2. (re-) Install numpy with option: $ sudo -H pip install --ignore-installed numpy
    DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. Collecting numpy Downloading https://files.pythonhosted.org/packages/bc/90/3e71b5392bd81d8559917ee38857bb2e4b92c88e87211a68e339127b86f5/numpy-1.16.2-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (13.9MB) 100% |████████████████████████████████| 13.9MB 921kB/s Installing collected packages: numpy Successfully installed numpy-1.16.2

Tan Nguyen
  • 21
  • 1
0

If you're using the brew version of python

brew uninstall numpy

If you're using the mac version of python:

python 2.7

pip uninstall numpy

python 3

pip3 uninstall numpy
SinOfWrath
  • 285
  • 2
  • 8
0

It worked for me using easy_install to update numpy.

sudo easy_install numpy

Rafael Rios
  • 536
  • 1
  • 6
  • 20
0

I faced this issue better go with installing "anaconda" as it will take care of all this.

Refer https://conda.io/docs/user-guide/install/macos.html