Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3 not working with NLTK 3

Tags:

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'
like image 282
SnarkShark Avatar asked Dec 25 '22 16:12

SnarkShark


2 Answers

On Mac OS X:

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

On Ubuntu:

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

Then:

# 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')
like image 121
alvas Avatar answered Jan 05 '23 07:01

alvas


Libraries don't carry over between python versions.

You need to install that library for python 3 too.

Python 2 + Python 3 + library

like image 45
Ayy Avatar answered Jan 05 '23 07:01

Ayy