在PyCharm中导入NLTK时出错
我在PyCharm里尝试导入NLTK这个库,但遇到了一个错误。我用的是Mac OS 10.5.8和Python 2.7.6。我完全是编程小白,所以如果我漏掉了什么基础知识,请多包涵。
安装包失败:安装nltk包时发生错误。
执行的命令是:
packaging_tool.py install --build-dir /private/var/folders/NG/NGoQZknvH94yHKezwiiT+k+++TI/-Tmp-/pycharm-packaging3166068946358630595.tmp nltk
这个命令的错误输出:
Downloading/unpacking nltk
Could not fetch URL https://pypi.python.org/simple/nltk/: There was a problem confirming the ssl certificate: <urlopen error [Errno 1] _ssl.c:507: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed>
Will skip URL https://pypi.python.org/simple/nltk/ when looking for download links for nltk
Could not fetch URL https://pypi.python.org/simple/: There was a problem confirming the ssl certificate: <urlopen error [Errno 1] _ssl.c:507: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed>
Will skip URL https://pypi.python.org/simple/ when looking for download links for nltk
Cannot fetch index base URL https://pypi.python.org/simple/
Could not fetch URL https://pypi.python.org/simple/nltk/: There was a problem confirming the ssl certificate: <urlopen error [Errno 1] _ssl.c:507: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed>
Will skip URL https://pypi.python.org/simple/nltk/ when looking for download links for nltk
Could not find any downloads that satisfy the requirement nltk
Cleaning up...
No distributions at all found for nltk
Storing complete log in /Users/Tom/.pip/pip.log
补充说明:好的,现在我已经成功通过命令行安装了NLTK,然后也能在PyCharm里安装它了——但只适用于Python 2.5.1解释器。如果我用Python 2.7.6来试,还是会出现上面的错误。这有关系吗?还是说我不需要担心,直接用2.5.1就可以了?
3 个回答
我遇到过这个问题(刚刚又遇到一次),我不太记得在哪里找到的解决办法,但这和openssl的版本以及本地证书有关(听起来像是对这些概念只懂一点的人说的)。我解决这个问题的方法是把pip降级:
easy_install pip==1.2.1
这样之后你就可以再次使用pip安装了。
我用的是PyCharm,但从来不通过PyCharm来安装包,我总是使用终端,主要用pip或者easy_install在我的虚拟环境中安装它们。也许你可以直接在终端中安装这个包。
sudo pip install nltk
(https://pypi.python.org/pypi/nltk)
或者
sudo easy_install nltk
(如果你没有安装pip的话)
然后在PyCharm中,确保在设置里把你的项目解释器设置为包含你已安装包的python路径。
你最好还是使用最新版本的pip(1.5.6),并告诉它你不在乎你的Python包的安全性:
pip install --allow-all-external --allow-unverified ntlk nltk
如果你真的想确保安装过程没有任何问题,你还可以告诉它不要覆盖任何已经安装的包:
pip install --upgrade --force-reinstall --allow-all-external --allow-unverified ntlk nltk
如果你遇到文件写入权限错误,可以加上sudo。