26

I did sudo pip install -U nltk as suggested by the nltk documentation. However, I am getting the following output:

Collecting nltk
  Downloading nltk-3.0.5.tar.gz (1.0MB)
    100% |████████████████████████████████| 1.0MB 516kB/s 
Collecting six>=1.9.0 (from nltk)
  Downloading six-1.9.0-py2.py3-none-any.whl
Installing collected packages: six, nltk
  Found existing installation: six 1.4.1
    DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
    Uninstalling six-1.4.1:
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 211, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 311, in run
    root=options.root_path,
  File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 640, in install
    requirement.uninstall(auto_confirm=True)
  File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 716, in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 125, in remove
    renames(path, new_path)
  File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 315, in renames
    shutil.move(old, new)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
    copy2(src, real_dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
    copystat(src, dst)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
    os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/tmp/pip-7dp3on-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

Basically, it is unable to upgrade six from 1.4.1 to 1.9.0. I tried to do that separately but got the same error.

I mention El Capitan because some people are facing problems for other python installation on El Capitan and I am wondering if this is due to that.

Does anyone know how to solve this problem?

Kevin Brown-Silva
  • 40,873
  • 40
  • 203
  • 237
proutray
  • 1,943
  • 3
  • 30
  • 48

7 Answers7

38

Here is the way how I fixed the issues:

First, install Xcode CLI:

xcode-select --install

Then reinstall Python:

sudo brew reinstall python

Finally, install nltk:

sudo pip install -U nltk

Hope it helps :)

nvg58
  • 891
  • 1
  • 8
  • 17
  • Even after following these steps I'm still getting an error: File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat os.chflags(dst, st.st_flags) – Chef1075 Oct 10 '15 at 13:31
  • 2
    No need for `sudo` on brew or nor neither in `pip`. There was a solution around in other posts that incur disabling security settings, but is dangerous. This the correct troubleshooting :) – 3manuek Apr 01 '16 at 15:12
17

I know there's plenty of 'brew boosters' out there, but you shouldn't need to use another python for something so basic. If a dependency is found by pip in /System, as they said on South Park 'you're going to have a bad time'. If you don't need to make this change system-wide, you can just pip install --user <package> and add $HOME/Library/Python/2.7/bin to your shell path (via ~/.bash_profile, etc.).

Sacrilicious
  • 1,051
  • 9
  • 13
8

both of these result in six version 1.41:

pip install --ignore-installed six

pip install awsebcli --upgrade --ignore-installed six

the brew workaround is the one that makes sense, imo. If Apple needs its own copy of Python for El Capitan, it can have it. Mine's now here: /usr/local/bin/python

Monte Hayward
  • 459
  • 2
  • 11
4

The system Python cannot be upgraded or changed by pip because of the brand new System Integrity Protection mechanism which disables all changes to the system directory by even 'root'. You can disable SIP from the recovery environment via directions available elsewhere (e.g. http://www.howtogeek.com/230424/how-to-disable-system-integrity-protection-on-a-mac-and-why-you-shouldnt/ ) but a better solution is to use the --user argument to install into your local directory:

pip install --user nltk

This will then leave nltk in your local home directory.

> python
>>> import nltk
>>> nltk
>>> <module 'nltk' from '/Users/yourusername/Library/Python/2.7/lib/python/site-packages/nltk/__init__.pyc'>

Clearly if you're trying to install something globally accessible that won't work, but if all you're trying to do is install stuff that you're going to run from your own user ID it works fine.

eric.green
  • 440
  • 3
  • 8
2

I had the same issue. I use brew to manage packages. so first you have to run brew doctor It will list the issues with your setup, correct them. In my case /usr/local was not writable so I had to fix it

Then run

brew reinstall python

This fixed my problem and I was then able to install packages using pip

saggu
  • 21
  • 1
2

Alrighty 'then:

the simple simple simple truth is a hybrid answer of a few others put forth here:

  1. System Integrity Protection limits access to /Library as a root Mac OS X System directory root.
  2. you don't even need sudo or reinstalling of system packages etc.
  3. pip install --user nltk works, "pip install -U ..." doesn't
  4. pip install --user uses the accessible $HOME/Library/Python/2.7/bin directory... that you can add to your shell path (via ~/.bash_profile, etc.).
  5. This is far more elegant than having multiple installs of python and needing brew etc.

Amen

0

If you had created the /usr/local directory already, then run this command in terminal:

sudo chown $(whoami):admin /usr/local && sudo chown -R $(whoami):admin /usr/local

from http://digitizor.com/2015/10/01/fix-homebrew-permissions-osx-el-capitan/

J. Ceron
  • 1,188
  • 10
  • 8