Python 3 not working with NLTK 3

时间:2015-08-07 01:56:47

标签: python nltk

I just updated to Python3... well, sort of. I can run both Python2.7.9 in the terminal and Python3. I also have NLTK3, which usually works with Python2.7, but there are some times when certain things don't work. Yet when I switch to Python3 in the MacOSX terminal, it won't let me import nltk (or anything else for that matter). Is there a simple fix for this?

>>> python 3
>>> import nltk
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
ImportError: no module named 'nltk'

2 个答案:

答案 0 :(得分:6)

在Mac OS X上:

# Install pip
$ curl bootstrap.pypa.io/get-pip.py | python
$ curl bootstrap.pypa.io/get-pip.py | python3

在Ubuntu上:

# Install pip
$ sudo apt-get install pip
$ sudo apt-get install pip3

然后:

# Install NLTK on python and python3
$ sudo pip install -U nltk
$ sudo pip3 install -U nltk
# Install Numpy
$ sudo pip install -U numpy
$ sudo pip3 install -U numpy
$ python
>>> import nltk
>>> nltk.download('all')

答案 1 :(得分:4)

Libraries don't carry over between python versions.

You need to install that library for python 3 too.

Python 2 + Python 3 + library