[英]Installing local packages with Python virtualenv --system-site-packages
I know this topic has been beat to death but I have not been able to find a solution to the problem I'm having on SO or elsewhere, so I suspect that there may be a bug somewhere in my system.我知道这个话题已经被打败了,但我一直无法找到解决我在 SO 或其他地方遇到的问题的方法,所以我怀疑我的系统中某处可能存在错误。
I am on an older RHEL 6 platform with Python 3.4.我在使用 Python 3.4 的较旧的 RHEL 6 平台上。 I am developing an application that will run on this platform that uses Qt.我正在开发一个将在使用 Qt 的平台上运行的应用程序。 I've installed all of the relevant libraries via yum
(eg qt-devel
, pyqt4-devel
, etc.) and now want to install my application package as an "editable" package using pip install -e mypkg
.我已经通过yum
安装了所有相关的库(例如qt-devel
、 pyqt4-devel
等),现在想使用pip install -e mypkg
将我的应用程序包安装为“可编辑”包。 I also have a couple of dependency requirements that are not on yum
and must be installed via pip
.我还有一些依赖项要求,它们不在yum
,必须通过pip
安装。
What I would like to do is create a virtualenv that "inherits" the system packages installed via yum
but allows me to pip install
my own packages into a virtualenv directory in my home directory.我想要做的是创建一个 virtualenv,它“继承”通过yum
安装的系统包,但允许我将自己的包pip install
到我的主目录中的 virtualenv 目录中。
From my Googling it looks like the best way to do this is to create a virtual env with the system's site packages directory:从我的谷歌搜索来看,最好的方法是使用系统的站点包目录创建一个虚拟环境:
$ python3 -m venv --system-site-packages ~/venv
However, when I try to install a package to this virtualenv's site-packages directory, it attempts to install it under /usr/lib
and I get a Permission denied
error.但是,当我尝试将包安装到此 virtualenv 的 site-packages 目录时,它尝试将其安装在/usr/lib
,但出现Permission denied
错误。
So it appears that the --system-site-packages
option makes my virtualenv completely share the site-packages directory from my system instead of using it as a "base", where further packages can be layered on top.因此,似乎--system-site-packages
选项使我的 virtualenv 完全共享了我系统中的 site-packages 目录,而不是将其用作“基础”,其中可以在顶部分层进一步的包。
This answer states that using pip install -I
should do what I want, but that does not appear to be the case: 这个答案指出,使用pip install -I
应该做我想做的事,但情况似乎并非如此:
(venv) $ pip3 install -I bitstring
...
error: could not create '/usr/lib/python3.4/site-packages/bitstring.py': Permission denied
Create the virtual environment without the --system-site-packages
switch.创建没有--system-site-packages
开关的虚拟环境。 After the environment was created go to the folder the environment was created in. It should have a file pyvenv.cfg
.创建环境后,转到创建环境的文件夹。它应该有一个文件pyvenv.cfg
。 Edit this file.编辑此文件。 It has (among other text) a line它有(在其他文本中)一行
include-system-site-packages = false
Change this line to:将此行更改为:
include-system-site-packages = true
Activate the environment.激活环境。 Module installations will now go to the virtual environment and the system site packages are visible too.模块安装现在将进入虚拟环境,并且系统站点包也可见。
With Python 3.8, it seems --system-site-packages
work as expected:使用 Python 3.8,似乎--system-site-packages
可以按预期工作:
python3 -m venv --system-site-packages myProject
cat myProject/pyvenv.cfg
home = /usr/bin
include-system-site-packages = true
version = 3.8.5
After installation astroid, isort, wrapt
, I got:安装astroid, isort, wrapt
后,我得到:
pip list -v
Package Version Location Installer
---------------------- -------------------- ------------------------------------------------------- ---------
apturl 0.5.2 /usr/lib/python3/dist-packages
astroid 2.4.2 /home/to/no/MR/auto-gen/lib/python3.8/site-packages pip
isort 5.6.4 /home/to/no/MR/auto-gen/lib/python3.8/site-packages pip
jedi 0.15.2 /usr/lib/python3/dist-packages
keyring 18.0.1 /usr/lib/python3/dist-packages
wrapt 1.12.1 /home/to/no/MR/auto-gen/lib/python3.8/site-packages pip
Already installed 'system' packages are taken from /usr/lib/python3/dist-packages
while locally (venv) installed packages from: /home/to/no/MR/auto-gen/lib/python3.8/site-packages
已经安装的“系统”包来自/usr/lib/python3/dist-packages
而本地(venv)安装的包来自: /home/to/no/MR/auto-gen/lib/python3.8/site-packages
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.