How to avoid “Permission denied” when using pip wi

2020-01-24 20:25发布

I attempt to deploy a Python package with pip in a virtual environment on an Ubuntu machine, but encounter a permission-related issue. For example:

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

terminates by:

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

I can't sudo, since it will install the package globally, and not within the virtual environment. I chowned site-packages; ls shows only directories related to easy_install, pip and setuptools, and nothing related to Markdown.

How to deploy a package in a virtual environment with pip without encountering permission-related errors?

8条回答
贼婆χ
2楼-- · 2020-01-24 20:48

You did not activate the virtual environment before using pip.

Try it with:

$(your venv path) . bin/activate

And then use pip -r requirements.txt on your main folder

查看更多
Animai°情兽
3楼-- · 2020-01-24 20:56

If you created virtual environment using root then use this command

sudo su

it will give you the root access and then activate your virtual environment using this

source /root/.env/ENV_NAME/bin/activate
查看更多
登录 后发表回答