Installing python packages in virtual environment [duplicate]

﹥>﹥吖頭↗ 提交于 2021-01-29 07:44:40

问题


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.


回答1:


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




回答2:


Either change the permissions of the virtual enviroment directory or recreate it without using sudo.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/27732911/installing-python-packages-in-virtual-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!