无法在Mac OS El Capitan上安装nltk

时间:2022-02-27 10:40:00

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

我按照nltk文档的建议做了sudo pip install -U nltk。但是,我得到以下输出:

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.

基本上,它无法将六个从1.4.1升级到1.9.0。我试图单独做,但得到了同样的错误。

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.

我提到El Capitan是因为有些人在El Capitan上面临其他python安装的问题,我想知道这是否是由于这个原因。

Does anyone know how to solve this problem?

有谁知道如何解决这个问题?

7 个解决方案

#1


38  

Here is the way how I fixed the issues:

以下是我解决问题的方法:

First, install Xcode CLI:

首先,安装Xcode CLI:

xcode-select --install

Then reinstall Python:

然后重新安装Python:

sudo brew reinstall python

Finally, install nltk:

最后,安装nltk:

sudo pip install -U nltk

Hope it helps :)

希望能帮助到你 :)

#2


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.).

我知道那里有很多'酿造助推器',但你不应该使用另一个python来做一些基本的东西。如果在/ System中找到依赖关系,正如他们在南方公园所说的那样,你将会度过一个糟糕的时光。如果您不需要在系统范围内进行此更改,则只需按下install --user 并将$ HOME / Library / Python / 2.7 / bin添加到shell路径(通过〜/ .bash_profile等。 )。

#3


8  

both of these result in six version 1.41:

这两个都导致六个版本1.41:

pip install --ignore-installed six

pip install --ignore-installed six

pip install awsebcli --upgrade --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

brew解决方案是有意义的,imo。如果Apple需要自己的El Capitan Python副本,它可以拥有它。我现在在这里:/ usr / local / bin / python

#4


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:

由于全新的系统完整性保护机制甚至“root”禁用了对系统目录的所有更改,因此无法通过pip升级或更改系统Python。您可以通过其他地方可用的指示从恢复环境中禁用SIP(例如http://www.howtogeek.com/230424/how-to-disable-system-integrity-protection-on-a-mac-and-why-you-不应该/)但更好的解决方案是使用--user参数安装到您的本地目录:

pip install --user nltk

pip install --user nltk

This will then leave nltk in your local home directory.

这将使nltk保留在您的本地主目录中。

> 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.

显然,如果你试图安装全局可访问的东西是行不通的,但是如果你要做的就是安装你将从你自己的用户ID运行的东西,它可以正常工作。

#5


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

我遇到过同样的问题。我用brew来管理包。所以首先你必须运行brew doctor它将列出你的设置问题,纠正它们。在我的情况下/ usr / local不可写,所以我不得不修复它

Then run

brew reinstall python

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

这解决了我的问题,然后我可以使用pip安装软件包

#6


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. 系统完整性保护将对作为根Mac OS X系统目录根目录的/ Library的访问限制为限制。

  3. you don't even need sudo or reinstalling of system packages etc.
  4. 你甚至不需要sudo或重新安装系统包等。

  5. pip install --user nltk works, "pip install -U ..." doesn't
  6. pip install --user nltk工作,“pip install -U ...”没有

  7. 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.).
  8. pip install --user使用可访问的$ HOME / Library / Python / 2.7 / bin目录...您可以添加到shell路径(通过〜/ .bash_profile等)。

  9. This is far more elegant than having multiple installs of python and needing brew etc.
  10. 这比多次安装python并需要brew等更优雅。

Amen

#7


0  

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

如果您已经创建了/ usr / local目录,那么在终端中运行以下命令:

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

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/

#1


38  

Here is the way how I fixed the issues:

以下是我解决问题的方法:

First, install Xcode CLI:

首先,安装Xcode CLI:

xcode-select --install

Then reinstall Python:

然后重新安装Python:

sudo brew reinstall python

Finally, install nltk:

最后,安装nltk:

sudo pip install -U nltk

Hope it helps :)

希望能帮助到你 :)

#2


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.).

我知道那里有很多'酿造助推器',但你不应该使用另一个python来做一些基本的东西。如果在/ System中找到依赖关系,正如他们在南方公园所说的那样,你将会度过一个糟糕的时光。如果您不需要在系统范围内进行此更改,则只需按下install --user 并将$ HOME / Library / Python / 2.7 / bin添加到shell路径(通过〜/ .bash_profile等。 )。

#3


8  

both of these result in six version 1.41:

这两个都导致六个版本1.41:

pip install --ignore-installed six

pip install --ignore-installed six

pip install awsebcli --upgrade --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

brew解决方案是有意义的,imo。如果Apple需要自己的El Capitan Python副本,它可以拥有它。我现在在这里:/ usr / local / bin / python

#4


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:

由于全新的系统完整性保护机制甚至“root”禁用了对系统目录的所有更改,因此无法通过pip升级或更改系统Python。您可以通过其他地方可用的指示从恢复环境中禁用SIP(例如http://www.howtogeek.com/230424/how-to-disable-system-integrity-protection-on-a-mac-and-why-you-不应该/)但更好的解决方案是使用--user参数安装到您的本地目录:

pip install --user nltk

pip install --user nltk

This will then leave nltk in your local home directory.

这将使nltk保留在您的本地主目录中。

> 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.

显然,如果你试图安装全局可访问的东西是行不通的,但是如果你要做的就是安装你将从你自己的用户ID运行的东西,它可以正常工作。

#5


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

我遇到过同样的问题。我用brew来管理包。所以首先你必须运行brew doctor它将列出你的设置问题,纠正它们。在我的情况下/ usr / local不可写,所以我不得不修复它

Then run

brew reinstall python

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

这解决了我的问题,然后我可以使用pip安装软件包

#6


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. 系统完整性保护将对作为根Mac OS X系统目录根目录的/ Library的访问限制为限制。

  3. you don't even need sudo or reinstalling of system packages etc.
  4. 你甚至不需要sudo或重新安装系统包等。

  5. pip install --user nltk works, "pip install -U ..." doesn't
  6. pip install --user nltk工作,“pip install -U ...”没有

  7. 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.).
  8. pip install --user使用可访问的$ HOME / Library / Python / 2.7 / bin目录...您可以添加到shell路径(通过〜/ .bash_profile等)。

  9. This is far more elegant than having multiple installs of python and needing brew etc.
  10. 这比多次安装python并需要brew等更优雅。

Amen

#7


0  

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

如果您已经创建了/ usr / local目录,那么在终端中运行以下命令:

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

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/