venv on Windows 11 with Python 3.13.7 includes global paths in sys.path despite include-system-site-packages = false, causing packages to be installed globally instead of in the venv
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug report
Bug description:
Description
When creating and activating a virtual environment with Python 3.13.7 on Windows 11, sys.path includes global Python paths (e.g., C:\Program Files\Python313\python313.zip, C:\Program Files\Python313\DLLs, etc.), even though pyvenv.cfg has include-system-site-packages = false. This causes python -m pip install <package> to install packages to the global site-packages (C:\Program Files\Python313\Lib\site-packages) instead of the virtual environment's site-packages.
This breaks virtual environment isolation, requiring --target for every install, which is not the expected behavior.
Steps to Reproduce
-
Install Python 3.13.7 from the official Windows installer, ensuring "Add python.exe to PATH" is checked.
-
Open PowerShell 7.5.2.
-
Create a test directory and virtual environment:
mkdir test_venv_bug
cd test_venv_bug
python -m venv .venv -
Activate the virtual environment:
..venv\Scripts\Activate.ps1 -
Check
sys.path:
python -c "import sys; print('\n'.join(sys.path))"
Expected: Only venv paths (e.g., C:\path\to\test_venv_bug\.venv, C:\path\to\test_venv_bug\.venv\Lib\site-packages).
-
Check
pyvenv.cfg(should haveinclude-system-site-packages = false):
Get-Content .venv\pyvenv.cfg -
Install a test package:
python -m pip install requests -
Verify installation location:
python -m pip list
Get-ChildItem -Path .venv\Lib\site-packages | findstr requests
Get-ChildItem -Path 'C:\Program Files\Python313\Lib\site-packages' | findstr requests
Expected: requests in .venv\Lib\site-packages; nothing in global.
Expected Behavior
sys.pathshould only include virtual environment paths (no globalC:\Program Files\Python313*paths).python -m pip installshould install to.venv\Lib\site-packages.
Actual Behavior
sys.pathincludes global paths:- C:\Program Files\Python313\python313.zip
- C:\Program Files\Python313\DLLs
- C:\Program Files\Python313\Lib
- C:\Program Files\Python313
- C:\Users\jdstr\Documents\GitHub\ndx_scalper.git.venv_ndx_scalper
- C:\Users\jdstr\Documents\GitHub\ndx_scalper.git.venv_ndx_scalper\Lib\site-packages
python -m pip install requestsinstalls to globalsite-packages(C:\Program Files\Python313\Lib\site-packages), with warnings like "Target directory C:\Program Files\Python313\Lib\site-packages\certifi already exists."python -m pip listin venv shows onlypip; packages are missing in venv.
Environment
- Python version: 3.13.7 (installed via official Windows installer)
- OS: Windows 11 24H2 (Build 26100.5074)
- Shell: PowerShell 7.5.2
pyvenv.cfgcontents:
home = C:\Program Files\Python313
include-system-site-packages = false
version = 3.13.7
executable = C:\Program Files\Python313\python.exe
command = C:\Program Files\Python313\python.exe -m venv C:\Users\jdstr\Documents\GitHub\ndx_scalper.git.venv_ndx_scalper
- Activated venv prompt:
(.venv) PS ... Get-Command pythonandGet-Command pippoint to venvScripts\python.exeandScripts\pip.exe.
Additional Notes
- Using
--target=.venv\Lib\site-packagesworks as a workaround, but it's cumbersome. - Searched GitHub issues and Stack Overflow—no exact match, but similar to older Windows venv path leaks (e.g., pip #11154).
- No antivirus or custom configs interfering (standard setup).
Minimal Reproducible Example
See "Steps to Reproduce" above. The test directory can be zipped and attached if needed.
Thanks for looking into this—it's breaking venv isolation on Windows.
CPython versions tested on:
3.13
Operating systems tested on:
Windows
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện báo cáo với python -m venv, Scripts\python.exe đã được kích hoạt và môi trường Windows Python 3.13.7 được nêu. So sánh sys.path, pyvenv.cfg và các đích do python -m pip báo cáo; được xem là hoàn tất khi các đường dẫn hệ thống bị loại trừ lúc include-system-site-packages = false và các gói cài đặt vẫn nằm trong venv.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- operating-systems, tooling
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 42/100