简体   繁体   English

在Mac OSX上安装ntlk时出现问题

[英]Problems installing ntlk on Mac OSX

I'm trying to install ntlk for a Django project. 我正在尝试为Django项目安装ntlk。 I followed the intstructions on NTLK's website, and I they worked because when I try to install again with pip, I get: 我按照NTLK网站上的说明进行了操作,我工作了,因为当我尝试再次使用pip安装时,我得到:

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

However, when I do import ntlk from python3, I get: 但是,当我从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
              ^

SyntaxError: invalid syntax SyntaxError:语法无效

import numpy works, however. 然而,导入numpy的工作。 Any help would be appreciated! 任何帮助,将不胜感激!

It seems you made a spelling mistake: 看来你拼错了:

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

And you're trying to import ntlk . 而你正在尝试import ntlk Try using import nltk . 尝试使用import nltk

As for the import error, the following from their website: 至于导入错误,以下来自他们的网站:

NLTK requires Python versions 2.6-2.7. NLTK需要Python版本2.6-2.7。 (A version supporting Python 3 is available at http://nltk.org/nltk3-alpha/ ). http://nltk.org/nltk3-alpha/上提供了支持Python 3的版本)。

So NLTK does not (yet) support python 3.3 fully. 所以NLTK还没有完全支持python 3.3。

First remove NLTK using pip: sudo pip uninstall nltk 首先使用pip删除NLTK: sudo pip uninstall nltk

Then download the source. 然后下载源代码。 And install using sudo python setup.py install 并使用sudo python setup.py install

And try again. 然后再试一次。 Be aware this is an alpha, so expect some methods to randomly throw errors or generate unexpected output. 请注意这是一个alpha,所以期望一些方法随机抛出错误或产生意外的输出。

If you still have this error after fixing the spelling, the issue is that PyPI is installing an older NLTK package (2.x). 如果在修复拼写后仍然出现此错误,则问题是PyPI正在安装较旧的NLTK程序包(2.x)。 Check this by looking at the first message in the terminal immediately after your run sudo pip install nltk . 通过在运行sudo pip install nltk后立即查看终端中的第一条消息来检查这sudo pip install nltk

To install the latest version of NLTK (3.x) that is compatible with Python 3, first sudo pip uninstall nltk . 要安装与Python 3兼容的最新版本的NLTK(3.x),首先是sudo pip uninstall nltk

Then use: 然后使用:

sudo pip install nltk==3.0.0b2

The latest version number is found here: https://pypi.python.org/pypi/nltk 最新版本号可在此处找到: https//pypi.python.org/pypi/nltk

Sometimes the versions of dependent packages may cause issues. 有时,依赖包的版本可能会导致问题。 The main issue is old, but I found a slightly different problem when using the parser - which internally was going into scipy. 主要问题是旧的,但是在使用解析器时我发现了一个稍微不同的问题 - 内部进入scipy。 Solved using: 解决了使用:

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

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

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