How can I use nltk library in cloud9?

python

#1

Hi there.

I want to use nltk in cloud9.
I tried to install nltk with pip but it says permission denied.
Is there way to use nltk in cloud 9?
thank you!


#2

Could you please post the commands you have tried so far? Most likely, the problem is that you need to install as root, so try running the command with sudo (i.e. sudo pip3 install nltk or sudo pip install nltk). If it still errors, please post those errors here and we can try to further diagnose the problem.


#3

pip install --user nltk into a virtualenv


#4

I also facing the same problem. I did try running the command with sudo but still there is a syntax error on ‘pip’ as shown below. Can someone help me.

sudo pip install nltk
^
SyntaxError: invalid syntax


#5

Create a virtualenv if you haven’t

$ virtualenv .

Start the env

$ source ./bin/activate

Your console will now look like

(workspace)kalinchernev:~/workspace $

workspace is the name of the virtualenv.

Then, install the dependency:

(workspace)kalinchernev:~/workspace $ pip install nltk

In an example file, put some hello world script

import nltk
nltk.download('punkt')

sentence = "At eight o'clock on Thursday morning Arthur didn't feel very good."

tokens = nltk.word_tokenize(sentence);

print(tokens)

From the terminal, run the script

$ python test.py

Output will be similar:

(workspace)kalinchernev:~/workspace $ python test.py 
[nltk_data] Downloading package punkt to /home/ubuntu/nltk_data...
[nltk_data]   Package punkt is already up-to-date!
['At', 'eight', "o'clock", 'on', 'Thursday', 'morning', 'Arthur', 'did', "n't", 'feel', 'very', 'good', '.']

In short, nothing special regarding installation when you have an environment.