Vladimir Vargas Vladimir Vargas - 7 days ago 6
Python Question

Installing python2 modules if default python is python3

I have installed Anaconda3 to get all the modules for python 3. However there are some codes which must be run in python 2. I don't have any installed python 2 module. I tried installing numpy via:

pip2.7 install numpy


But got an error:


OSError: [Errno 13] Permission denied:
'/usr/local/lib/python2.7/dist-packages/numpy'


Whenever I want to install a module I get the same error, for instance, with the NLTK module I get


OSError: [Errno 13] Permission denied:
'/usr/local/lib/python2.7/dist-packages/nltk-3.2.1.dist-info'


How can I fix this?

Thanks!

Answer

If you don't have sudo or otherwise proper permissions, you might try installing in a user-writable directory via the "user" flag:

pip2 install --user numpy

The location is customizable with the PYTHONUSERBASE variable. Read all about it (and more) here: https://pip.pypa.io/en/stable/user_guide/#user-installs

Comments