Lucas Abbade
Lucas Abbade

Reputation: 817

PermissionError when downloading NLTK data

I use Anaconda's Python 3.6.3 distribution and it comes with NLTK installed, but not with NLTK DATA, which I need for a project, the problem is, when I try to install with

nltk.download()

I get

PermissionError: [Errno 13] Permission denied: '/usr/share/nltk_data'

So, I did some research, and I see people suggesting to run Python as

sudo python

but if I do that, it will launch the base Linux's Python, not Anaconda's.

tl;dr

I need some way to do something like

sudo conda python

If you have other suggestions that might work, I'll take it too.

Thanks!

Upvotes: 2

Views: 8553

Answers (2)

alvas
alvas

Reputation: 122142

Find out which directory you can write files to. E.g. if it's /home/alvas/testdir

Then

>>> pip install -U nltk
>>> mkdir -p /home/alvas/testdir 
>>> python -m nltk.download popular -d /home/alvas/testdir 

If you want to know how to configure the custom path for nltk_data, at the start of your Python code:

import nltk
nltk.data.path.append('/home/alvas/testdir')

Upvotes: 5

arnaud
arnaud

Reputation: 3483

Would something like this work ? Supposing your Anaconda env is called myenv.

source activate myenv
sudo python -c "import nltk; nltk.download()"

That's assuming having activated your env before would prevent using the base Linux's Python as you pointed out.

Upvotes: 0

Related Questions