python / python/cpython

On Windows, VENV does not copy pip module into a new created virtual environments

Đang mở
#139,018 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

stdlib topic-venv type-bug
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:

When creating a new isolated environment via VENVE, module pip is not installed and does not exist in Lib/site-packages. The command pip is available but still operates on non-virtual environment level.

Specification
  • Windows 10 Home (22H2)
  • PowerShell 7.5.3
  • Python 3.13.7
  • Launcher (py.exe).
Steps to reproduce the issue
  • Run py -m venv .venv
  • Activate environment: .\ .venv\Scripts\Activate.ps1
  • Try to upgrade pip: python -m pip install pip --upgrade
  • Python will report the error that pip is not installed.

Other distribution s.a. 3.12 and 3.11 have the same issue.

Description

I simply run the following command py -m venv .venv to create a new environment, followed by activation .venv\Scripts\Activate.ps1. I've got a new prompt (.venv) PS D ...> . The Get-Command python indicates the correct path to python.exe: <local path>\.venv\Scripts\python.exe.

Here's the problem. After activating new environment, while pip is still available as a standalone program, it does not work on a local level. If I try to run pip install numpy --dry-run, I get the report

Requirement already satisfied: numpy in <user>\appdata\local\programs\python\python313\lib\site-packages (2.3.3)

I believe pip should work on a local level. BTW, if I run the command Get-Command pip, the path to pip is

<User>\AppData\Local\Programs\Python\Python313\Scripts\pip.exe
Impossible to install new modules

This obviously leads to the problem of not being able to install new modules in newly created environments because pip is missing. For instance python -m pip install pip --upgrade issues the error

`<local path>\.venv\Scripts\python.exe: No module named pip

while python still works as expected, that is Get-Command python outputs

<local path>\.venv\Scripts\python.exe

I can also run Get-Children -Recurse -Path ".venv/" to check local Lib/site-packages

    Directory: <Local Path>\.venv

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----          16/09/2025    12:20                Include
d----          16/09/2025    12:20                Lib
d----          16/09/2025    12:20                Scripts
-a---          16/09/2025    12:20             71 .gitignore
-a---          16/09/2025    12:20            338 pyvenv.cfg

    Directory: <Local Path>\.venv\Lib

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----          16/09/2025    12:20                site-packages

    Directory: <Local Path>\.venv\Scripts

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          16/09/2025    12:20           2208 activate
-a---          16/09/2025    12:20           1022 activate.bat
-a---          16/09/2025    12:20           2281 activate.fish
-a---          06/08/2025    16:16           9031 Activate.ps1
-a---          06/08/2025    16:14            393 deactivate.bat
-a---          06/08/2025    16:15         255320 python.exe
-a---          06/08/2025    16:15         251736 pythonw.exe

    Directory: <Local Path>\__pycache__

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          29/07/2024    16:12          15096 backup.cpython-312.pyc

but the folder Lib/site-packages is empty. please, note Get-Children -Recurse ignores empty folders in further iteration.


Possible workarounds

The only working workaround is to copy pip and pip-25.2.dist-info from global Lib/site-packages into isolated environment's Lib/site-packages.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với entry point py -m venv .venv và tái hiện các lệnh Windows PowerShell được mô tả trong báo cáo. Kiểm tra cách môi trường mới khởi tạo pip và xác minh kết quả dựa trên thư mục Lib/site-packages trống; được xem là hoàn tất khi pip khả dụng thông qua Python của môi trường thay vì bản cài đặt toàn cục.

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
tooling
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 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
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.