简体   繁体   English

无法在Mac OS El Capitan上安装nltk

[英]Unable to install nltk on Mac OS El Capitan

I did sudo pip install -U nltk as suggested by the nltk documentation. 我按照nltk文档的建议做了sudo pip install -U nltk 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. 基本上,它无法从1.4.1升级到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. 我提到El Capitan是因为有些人在El Capitan上遇到其他python安装的问题,我想知道这是否是由于这个原因。

Does anyone know how to solve this problem? 有谁知道如何解决这个问题?

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 :) 希望能帮助到你 :)

I know there's plenty of 'brew boosters' out there, but you shouldn't need to use another python for something so basic. 我知道那里有很多'酿造助推器',但你不应该使用另一个python来做一些基本的东西。 If a dependency is found by pip in /System, as they said on South Park 'you're going to have a bad time'. 如果依赖是通过发现pip / System中,因为他们在南园说:“你将有一个坏的时间”。 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.). 如果您不需要在系统范围内进行此更改,则只需pip install --user <package>并将$HOME/Library/Python/2.7/bin到shell路径(通过~/.bash_profile等。 )。

both of these result in six version 1.41: 这两个都导致六个版本1.41:

pip install --ignore-installed six

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

the brew workaround is the one that makes sense, imo. brew解决方案是有意义的,imo。 If Apple needs its own copy of Python for El Capitan, it can have it. 如果Apple需要自己的El Capitan Python副本,它可以拥有它。 Mine's now here: /usr/local/bin/python 我现在在这里: /usr/local/bin/python

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'. 由于全新的系统完整性保护机制甚至“root”禁用了对系统目录的所有更改,因此无法通过pip升级或更改系统Python。 You can disable SIP from the recovery environment via directions available elsewhere (eg 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: 您可以通过其他地方提供的指示从恢复环境中禁用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运行的东西,那么它可以正常工作。

I had the same issue. 我遇到过同样的问题。 I use brew to manage packages. 我用brew来管理包。 so first you have to run brew doctor It will list the issues with your setup, correct them. 所以首先你必须运行brew doctor它将列出你的设置问题,纠正它们。 In my case /usr/local was not writable so I had to fix it 在我的情况下/ usr / local不可写,所以我不得不修复它

Then run 然后跑

brew reinstall python

This fixed my problem and I was then able to install packages using pip 这解决了我的问题,然后我可以使用pip安装包

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. 系统完整性保护将对作为根Mac OS X系统目录根目录的/ Library的访问权限限制。
  2. you don't even need sudo or reinstalling of system packages etc. 你甚至不需要sudo或重新安装系统包等。
  3. pip install --user nltk works, "pip install -U ..." doesn't pip install --user nltk工作,“pip install -U ...”没有
  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.). pip install --user使用可访问的$ HOME / Library / Python / 2.7 / bin目录...您可以添加到shell路径(通过〜/ .bash_profile等)。
  5. This is far more elegant than having multiple installs of python and needing brew etc. 这比多次安装python并需要brew等更优雅。

Amen 阿门

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/ 来自http://digitizor.com/2015/10/01/fix-homebrew-permissions-osx-el-capitan/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM