13

I am attempting to install django to a virtualenv that already exists.

Following the instructions listed on the pip-install website here, I ran the following from SSH.

name@server:~$ . myenv.env/bin/activate
(myenv.env)nam@server:~$ pip install django

However at the bottom of the installation, I am seeing this:

creating /usr/local/lib/python2.7/dist-packages/django

error: could not create '/usr/local/lib/python2.7/dist-packages/django': Permission denied

It appears that it is trying to install it to the global directory. I do not have sudo privileges. Am I doing something wrong here?

Update: $PATH = /var/django/myenv.env/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

8 Answers8

8

Sorry for a year late answer! I had the same problem and fixed it, I don't know if you changed the name of a directory after creating the virtual environment, I did though. If so then here's what I did.

1.) deactivate your v-env. After the fix you need to restart the v-env, so might as well deactivate now. right?

2.) Now, since we created the v-env in a different path, we have to change the static path variables in these files.

To get pip working you don't need to do this, but I still do. bin/activate, bin/activate.csh, bin/activate.fish

bin/pip, bin/pip2, bin/pip2.7

bin/easy_install, bin/easy_install2.7

3.) To get pip working, you must correct the python interpreter in the pip file, this as well has a static interpreter location set by virtualenv in the creation process.

4.) To get easy_install working? You guessed it, fix the interpreter location.

I hope this helped for any people reading this in the future. Sorry OP, for being late.

Crispy
  • 196
4

I had this same problem.

I deleted the virtual environment and created a new one, which solved the problem.

Probably not the answer you were hoping for, but since it's the only one...

Mark
  • 251
1

Calling sudo pip will call global pip and not pip in your virtualenv. Activate/Workon your environment then just call pip, not sudo pip, this may fix your issue, as it did mine.

Marco
  • 1,864
1

Well without administrative privileges you're very limited on what you are able to do. If you are not allowed to elevate yourself or ask for privileges, the best way I found to go about that would be to create another environment, make a requirements.txt file, download all the packages you need to your machine( django ) that would also be located in your requirements file and it should work.

secure212
  • 228
0

In may case I had upgraded my main python version and this was not reflected in the virtualenv. So to upgrade pip, make sure your virtualenv is activated, then run

python -m ensurepip --upgrade
Psionman
  • 101
0

Had the same problem. In my case the reason was that the created virtual env was for python2.7 (the default) but I was using pip3 to install a package. pip3 was not present in my virtualenv so it defaulted to the global one. For me the fix was to use

virtualenv flask --python=python3

to create the env.

Adversus
  • 121
0

I had encountered the same problem caused by renaming of user. Crispy's answer is totally right. And my solution may be more convenient.

setps:
1. Enter your virtual environment's bin path, such as cd ~/virenv_dir/bin
2. Rename all files under this directory using sed command. sed -i 's/old_name/new_name/' *

xialu
  • 101
0

In my case, I had defined two aliases (to overcome some other issue on the default python version):

alias pip='/usr/bin/pip3'
alias python='/usr/bin/python3'

And this was causing the same symptoms:

[Errno 13] Permission denied: '/usr/lib/python3.6/site-packages'

Removing the aliases solved the issue (before or after creating the virtualenv)

coderazzi
  • 101