2014-01-17 166 views
0

我正在尝试为Django项目安装ntlk。我也跟着上NTLK网站上的intstructions,和我他们的工作,因为当我尝试使用PIP重新安装,我得到:在Mac OSX上安装ntlk的问题

➜ Word_Maker git:(master) sudo pip install -U numpy 
Requirement already up-to-date: numpy in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages 
Cleaning up... 
➜ Word_Maker git:(master) sudo pip install -U pyyaml nltk 
Requirement already up-to-date: pyyaml in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages 
Requirement already up-to-date: nltk in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages 
Cleaning up... 

然而,当我从python3做进口ntlk,我得到:

Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 16 2013, 23:39:35) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import nltk 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/nltk/__init__.py", line 37 
    except IOError, ex: 
       ^
SyntaxError: invalid syntax 
      ^

语法错误:无效语法

但是,导入numpy作品。任何帮助,将不胜感激!

+0

要求已更新:'nltk' in ... 而您正在尝试“import ntlk'。尝试使用'import nltk'。即检查拼写 – EWit

+0

哇,真是愚蠢的错误。现在,我收到了这个错误:Python 3.3.3(v3.3.3:c3896275c0f6,2013年11月16日,23:39:35) [GCC 4.2.1(Apple Inc. build 5666)(dot 3)] darwin 输入“帮助”,“版权”,“信用”或“许可证”以获取更多信息。 >>>进口NLTK 回溯(最近通话最后一个): 文件 “”,1号线,在 文件“/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-包/ NLTK/__ init__。py“,第37行 除了IOError,例如: ^ SyntaxError:无效的语法 – goodcow

回答

1

看来你犯了一个拼写错误:

Requirement already up-to-date: nltk in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages 

而且你想import ntlk。尝试使用import nltk

至于进口错误,从他们的网站如下:

NLTK requires Python versions 2.6-2.7. (A version supporting Python 3 is available at http://nltk.org/nltk3-alpha/).

所以NLTK没有(还)支持的Python 3.3完全。

首先使用PIP删除NLTK:sudo pip uninstall nltk

然后下载源。并安装使用sudo python setup.py install

然后再试一次。请注意这是一个alpha,所以期望一些方法随机抛出错误或产生意想不到的输出。

1

如果修复拼写后仍然存在此错误,则问题是PyPI正在安装较旧的NLTK包(2.x)。在运行sudo pip install nltk后立即查看终端中的第一条消息来检查。

要安装与Python 3兼容的最新版本的NLTK(3.x),请首先安装sudo pip uninstall nltk

然后使用:

sudo pip install nltk==3.0.0b2 

最新版本号在这里找到:https://pypi.python.org/pypi/nltk

+0

这应该是最好的答案 –

+0

硬编码版本可能不是一个持久的解决方案,也许完全安装与-U是更好的时间这个问题的独立解决方案也被称为答案。 – vpathak

0

有时依赖包的版本可能会导致问题。主要问题是旧的,但是当使用解析器时,我发现一个稍微不同的问题 - 内部正在进入scipy。已解决使用:

pip3 uninstall nltk scipy matplotlib 
pip3 install -U nltk scipy matplotlib