Avoiding "Failure Resolution" when using pip with virtualenv

I am trying to deploy a Python package with pip in a virtual environment on an Ubuntu machine, but have encountered a permission problem. For example:

 (TestVirtualEnv)test@testServer:~$ pip install markdown2 

ends with:

error: failed to create '/home/test/virtualenvs/TestVirtualEnv/lib/python3.3/site-packages/markdown2.py': Permission denied

I cannot sudo since it will install the package all over the world and not in a virtual environment. I am chown ed site-packages ; ls only directories related to easy_install , pip and setuptools displayed, and nothing related to Markdown.

How to deploy a package in a virtual environment using pip without encountering rights errors?

+84
python pip virtualenv
Oct 19 '13 at 22:46
source share
6 answers

virtualenv Resolution problems can occur when creating virtualenv as sudo and then working without sudo in virtualenv .

As it turned out in your interrogative comment, the solution here is to create virtualenv without sudo in order to be able to work (esp. Write) in it without sudo .

+93
Oct 19 '13 at 23:02
source share

Decision:

If you created virtualenv as root, run the following command:

 sudo chown -R your_username:your_username path/to/virtuaelenv/ 

This will probably fix your problem.

Greetings

+86
Mar 11 '15 at 10:42
source share

I did not create my virtualenv using sudo. Therefore, Sebastian's answer did not concern me. My project is called utils . I checked the utils directory and saw this:

 -rw-r--r-- 1 macuser staff 983 6 Jan 15:17 README.md drwxr-xr-x 6 root staff 204 6 Jan 14:36 utils.egg-info -rw-r--r-- 1 macuser staff 31 6 Jan 15:09 requirements.txt 

As you can see, utils.egg-info belongs to root not macuser . That's why it gave me permission denied error. I also had to remove /Users/macuser/.virtualenvs/armoury/lib/python2.7/site-packages/utils.egg-link since it was created by root . I did pip install -e . again pip install -e . after removing them, and it worked.

+4
Jan 08 '15 at 19:04
source share

In my case, I used mkvirtualenv , but did not say that I would use python3. I got this error:

 mkvirtualenv hug pip3 install hug -U .... error: could not create '/usr/lib/python3.4/site-packages': Permission denied 

It worked after specifying python3:

 mkvirtualenv --python=/usr/bin/python3 hug pip3 install hug -U 
+4
Dec 22 '16 at 5:20
source share

You did not activate the virtual environment before using pip.

Try:

 $(your venv path) . bin/activate 

And then use the pip -r requirements.txt file in your main folder

+1
Aug 08 '17 at 11:59 on
source share

When creating virtualenv, if you use sudo, the directory is created with root privileges. Therefore, when you try to install a package with a non-sudo user, you will not have permission to install it. Therefore, always create virtualenv without sudo and install without sudo.

You can also copy packages installed on global python to virtualenv.

 cp -r /lib/python/site-packages/* virtualenv/lib/python/site-packages/ 
0
Sep 16 '17 at 13:40
source share



All Articles