无法在 Venv 中使用 Pip [英] Cannot Use Pip Within Venv

查看:75
本文介绍了无法在 Venv 中使用 Pip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多类似的问题,但我都问了一遍都无济于事.

I'm aware there are many similar questions but I have been through them all to no avail.

在 Ubuntu 18.04 上,我有 Python 2 和 Python 3.6.我使用下面的命令创建了一个 venv 并尝试使用 pip 安装一个包.但是,它会尝试安装在全局系统上,而不是安装在 venv 中.

On Ubuntu 18.04, I have Python 2 and Python 3.6. I create a venv using the command below and attempt to install a package using pip. However, it attempts to install on the global system and not in the venv.

python3 -m venv v1

python3 -m venv v1

当我运行which python"时,它会正确选择 venv 中的 python.我检查了他的 v1/bin 文件夹并安装了 pip.pip 脚本中的路径正确指向 venv 中的 python.

When I run 'which python' it correctly picks the python within the venv. I have checked he v1/bin folder and pip is installed. The path within the pip script is correctly pointed to toward python in the venv.

我尝试过重新安装python3和venv,破坏和重新创建虚拟环境以及许多其他事情.想知道有没有一些合理的方法来理解和解决这个问题.

I have tried reinstalling python3 and venv, destroying and recreating the virtual environment and many other things. Wondering is there some rational way to understand and solve this.

推荐答案

就我而言,问题是我正在处理的已安装驱动器未安装为可执行文件.所以 pip 无法从 mount 上的 venv 内执行.

The problem in my case was that the mounted drive I was working on was not mounted as executable. So pip couldn't be executed from within the venv on the mount.

这是确认的,因为我能够使用python -m pip install numpy"进行 pip 安装,但是在导入库时,例如'import numpy',然后面临进一步的错误:

This was confirmed because I was able to get a pip install using 'python -m pip install numpy' but when importing libraries, e.g. 'import numpy', was then faced with further error of:

multiarray_umath.cpython-36m-x86_64-linux-gnu.so:无法从共享对象映射段

multiarray_umath.cpython-36m-x86_64-linux-gnu.so: failed to map segment from shared object

根据下面的 github 问题导致权限问题.由 dvdabelle 在评论中修复该问题,然后修复相关和原始问题.

which led back to the permissions issue as per github issue below. Fix for that by dvdabelle in comments then fixes dependent and original issue.

https://github.com/numpy/numpy/issues/15102

在他的情况下,他可以切换驱动器.我必须使用这个驱动器.因此,修复方法是卸载我正在工作的/data 磁盘,然后使用 exec 选项重新安装它!

In his case, he could just switch drive. I have to use this drive. So the fix was to unmount my /data disk where I was working and remount it with exec option!

sudo 卸载/data

sudo umount /data

sudo mount -o exec/dev/sda4/data

sudo mount -o exec /dev/sda4 /data

'which pip' 现在正确指向 venv 中的 pip

'which pip' now points to the pip in the venv correctly

注意:要使其永久添加 exec 开关到 fstab 中驱动器的行,按照 https://download.tuxfamily.org/linuxvillage/Informatique/Fstab/fstab.html(使 exec 作为选项中的最后一个参数,否则用户将覆盖它)例如

Note: to make it permanent add the exec switch to the line for the drive in fstab as per https://download.tuxfamily.org/linuxvillage/Informatique/Fstab/fstab.html (make exec the last parameter in the options or user will override it) E.g.

UUID=1332d6c6-da31-4b0a-ac48-a87a39af7fec/data auto rw,user,auto,exec 0 0

UUID=1332d6c6-da31-4b0a-ac48-a87a39af7fec /data auto rw,user,auto,exec 0 0

这篇关于无法在 Venv 中使用 Pip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆