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 摘要。