python / python/cpython

Virtual environments created with `venv --system-site-packages` can't access binaries from pre-installed packages, neither re-install those packages

未关闭
#118,388 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

type-bug
主要语言
Python
星标
77.2k
派生
36k
PR 合并指标
PR 指标待抓取

描述

Bug report

Bug description:

I wanted to "pre-install" in my "source" python installation some packages I often use, so that those packages are readily available in the virtual environments created from this "source", without wasting space and time re-installing them every time I create a new venv.

I thought the --system-site-packages would do just that, however, this "doesn't work" for binaries installed by python packages (for instance, ipython, but I can think of other cases like pylint, flake8 or cookieninja):

I create the venv (using a locally compiled 3.11 version):

bli@latimeria:~/tmp$ ~/python3.11/bin/python3 -m venv --system-site-packages .venv
bli@latimeria:~/tmp$ source .venv/bin/activate

However, the bin directory of the venv does not contain ipython:

(.venv) bli@latimeria:~/tmp$ ls .venv/bin/ | grep ipython

But ipython is installed in the source python 3.11:

(.venv) bli@latimeria:~/tmp$ ls ~/python3.11/bin/ | grep ipython
ipython
ipython3

This is however not in the PATH when in the venv (in this particular case, calling ipython starts one installed with python 3.6 in ${HOME}/bin, whereas if I try with a package not installed anywhere else than in the python 3.11 install, like cookieninja, the command is not found).

This even prevents the installation of ipython in the venv:

(.venv) bli@latimeria:~/tmp$ .venv/bin/pip3 install ipython
Requirement already satisfied: ipython in /home/bli/python3.11/lib/python3.11/site-packages (8.24.0)
[...]
(.venv) bli@latimeria:~/tmp$ .venv/bin/pip3 install --upgrade ipython
Requirement already satisfied: ipython in /home/bli/python3.11/lib/python3.11/site-packages (8.24.0)
[...]
CPython versions tested on:

3.11

Operating systems tested on:

Linux

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用 python -m venv --system-site-packages、激活操作,以及安装在源 Python 中的 ipython 或 cookieninja 等软件包重现该问题。比较 venv PATH 和 pip install 或升级行为;验证了对预安装软件包二进制文件的预期访问权限以及软件包安装行为后,即视为完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
tooling
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。