简体   繁体   English

在虚拟环境中安装python软件包

[英]Installing python packages in virtual environment

I'm trying to install django in a virtual environment. 我正在尝试在虚拟环境中安装django。 I'm in a virtual environment, but when i type pip install django I get a permission denied error. 我在虚拟环境中,但是当我输入pip install django出现权限被拒绝错误。 If I try to run sudo pip install django , however, I get sudo: pip: command not found . 但是,如果尝试运行sudo pip install djangosudo pip install django得到sudo: pip: command not found Not entierly sure where to go from here. 不能完全确定从这里出发。

更改虚拟环境目录的权限或不使用sudo重新创建它。

Since you setup your virtual environment with sudo virtualenv /opt/myenv , you now need to run the correct pip instance (ie the one inside your newly created virtual environment). 由于您使用sudo virtualenv /opt/myenv设置了虚拟环境,因此您现在需要运行正确的pip实例(即,新创建的虚拟环境中的一个实例)。

Therefore, your command needs to be sudo /opt/myenv/bin/pip install django 因此,您的命令需要是sudo /opt/myenv/bin/pip install django

If you are using python 2.7.6 to upgrade to python 3.4 in virtualenvironment 如果您使用python 2.7.6在虚拟环境中升级到python 3.4

(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 接下来使用最新的python包覆盖您之前的包

$ 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 您可以检查3.4软件包是否已被覆盖

(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. 这帮助我使用了覆盖了Python 2.7.6的python 3.4软件包,因为我是python编程语言的新手,所以我已经使用了4个月。

I hope if this could help you. 我希望这能对您有所帮助。

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). 现在最安全的操作是删除虚拟环境,并确保使用用户权限重新创建它(没有sudo)。 And as a side note, the command not found error is due to pip not being set up for root. 另外,未找到命令错误是由于未为root设置pip。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM