问题描述
如果我在virtualevn中使用具有sudo权限的pip/pip3安装某些东西,会发生什么情况?
What does happen if I install something using pip/pip3 with sudo privilege in virtualevn?
在virtualenv内使用pip3安装tensorflow时出现PermissionError,所以我使用sudo.
I got PermissionError while installing tensorflow with pip3 inside virtualenv, so I used sudo.
(.tensorflow) $ pip3.5 install tensorflow
...
PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.5/site-packages'
(.tensorflow) $ sudo pip3.5 install tensorflow
然后我可以在virtualenv之外的ipython3中导入tensorflow.
Then I can import tensorflow in ipython3 outside virtualenv.
但是,使用pip2安装时没有出现PermissionError.
However, I did not get PermissionError when I installed using pip2.
因此,如果我使用sudo特权在virtualenv内安装了某些软件,可以从外部访问它吗?
So, if I install something inside virtualenv with sudo privilege, is it accessible from outside?
谢谢.
推荐答案
您的virtualenv是否使用Python 3.5作为其解释器?您可以通过在启用virtualenv的情况下仅运行python --version
来进行检查.根据您的陈述,我怀疑您有一个2.7 virtualenv.由于virtualenv是2.7,因此pip3.5
在虚拟环境的上下文中无法运行,这就是为什么您需要使用sudo
的原因. virtualenv -p python3.5 myvenvname
应该给您您想要的东西.
Is your virtualenv using Python 3.5 as its interpreter? You can check this by just running python --version
with the virtualenv activated. Based on your statements I suspect you have a 2.7 virtualenv. Since the virtualenv is 2.7 pip3.5
is not operating within the context of the virtual environment, which is why you needed to use sudo
. virtualenv -p python3.5 myvenvname
should give you what you want.
这篇关于如果在Python Virtualenv中使用Sudo Pip会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!