2

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!

Lucas Abbade
  • 757
  • 9
  • 19
  • Which OS are you using, Mac or Linux? Which setup are you in? Did you create an awesome/gcp instance? Use someone else's instance? Or did you install an os fresh from your machine? Or are you using a school computer with your account? Which directory so you have access to to save your files? Have you tried – alvas Feb 05 '18 at 23:59
  • I'm using Ubuntu 17.10, it's freshly installed in a new, personal machine, I have complete access/control over everything – Lucas Abbade Feb 06 '18 at 10:23

2 Answers2

4

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')
alvas
  • 115,346
  • 109
  • 446
  • 738
0

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.

arnaud
  • 3,293
  • 1
  • 10
  • 27