I'm trying to install django in a virtual environment. I'm in a virtual environment, but when i type pip install django
I get a permission denied error. If I try to run sudo pip install django
, however, I get sudo: pip: command not found
. Not entierly sure where to go from here.

- 41
- 1
- 1
- 4
-
Did you create your virtualenv using `sudo`? – Ffisegydd Jan 01 '15 at 17:21
-
How did you setup your virtualenviorment? I think you have problem in your setup. Usually `pip install django` works fine- – Koogle Jan 01 '15 at 17:21
-
I set up my virtual enviroment usign `sudo virtualenv /opt/myenv` – user3199345 Jan 01 '15 at 17:25
-
3Does this answer your question? [How to install a package inside virtualenv?](https://stackoverflow.com/questions/21240653/how-to-install-a-package-inside-virtualenv) – user202729 Jan 17 '21 at 16:47
4 Answers
Since you setup your virtual environment with sudo virtualenv /opt/myenv
, you now need to run the correct pip instance (i.e. the one inside your newly created virtual environment).
Therefore, your command needs to be sudo /opt/myenv/bin/pip install django

- 10,664
- 4
- 46
- 58
Either change the permissions of the virtual enviroment directory or recreate it without using sudo.

- 8,985
- 4
- 27
- 25
If you are using python 2.7.6 to upgrade to python 3.4 in virtualenvironment
(venv)$python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
First step is deactivating the virtual environment you have been using
(venv)$ deactivate
Next overriding your previous package with latest python package
$ virtualenv -p /usr/bin/python3.4 venv
next, activating the virtual environment
$ source venv/bin/activate
you can check to see if the package 3.4 has been overrided or not
(venv)$ python
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
This helped me to use the python 3.4 package overriding python 2.7.6 which i have been using from 4 months as I'm a newbie to python programming language.
I hope if this could help you.

- 902
- 2
- 11
- 25
This is a permissions issue and caused by how the virtual environment has been set up. The safest thing to do now is to remove the virtual environment and make sure to recreate it with the user's permissions (no sudo). And as a side note, the command not found error is due to pip not being set up for root.

- 3
- 3