You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows11下Python虚拟环境无法找到pip模块问题求助

Python 3.9虚拟环境(venv)中pip缺失问题排查与解决

在Windows 11系统中使用Python 3.9创建并激活虚拟环境(venv)后,出现无法找到pip模块的问题,执行ensurepip命令显示安装成功但问题仍未解决。

控制台输出详情

1. 未激活虚拟环境时的pip版本

PS C:\Users\qnehd\workplace\Python\py-ui> python -m pip --version
pip 23.0.1 from C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\site-packages\pip (python 3.10)

2. 激活虚拟环境后执行pip的报错

(venv) PS C:\Users\qnehd\workplace\Python\py-ui> python -m pip --version  
C:\Users\qnehd\workplace\Python\py-ui\venv\Scripts\python.exe: No module named pip  

(venv) PS C:\Users\qnehd\workplace\Python\py-ui> pip --version  
Traceback (most recent call last):  
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 196, in _run_module_as_main  
    return _run_code(code, main_globals, None,  
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 86, in _run_code  
    exec(code, run_globals)  
  File "C:\Users\qnehd\workplace\Python\py-ui\venv\Scripts\pip.exe\__main__.py", line 4, in <module>  
ModuleNotFoundError: No module named 'pip'

3. 执行ensurepip -vv的输出

(venv) PS C:\Users\qnehd\workplace\Python\py-ui> python -m ensurepip -vv
Using pip 23.0.1 from C:\Users\qnehd\AppData\Local\Temp\tmpq5tcirqh\pip-23.0.1-py3-none-any.whl\pip (python 3.10)
Non-user install because user site-packages disabled
Ignoring indexes: https://pypi.org/simple
Created temporary directory: C:\Users\qnehd\AppData\Local\Temp\pip-build-tracker-wlgbodxs
Initialized build tracking at C:\Users\qnehd\AppData\Local\Temp\pip-build-tracker-wlgbodxs
Created build tracker: C:\Users\qnehd\AppData\Local\Temp\pip-build-tracker-wlgbodxs
Entered build tracker: C:\Users\qnehd\AppData\Local\Temp\pip-build-tracker-wlgbodxs
Created temporary directory: C:\Users\qnehd\AppData\Local\Temp\pip-install-03524hs8
Created temporary directory: C:\Users\qnehd\AppData\Local\Temp\pip-ephem-wheel-cache-uttjzu10
Looking in links: c:\Users\qnehd\AppData\Local\Temp\tmpq5tcirqh
0 location(s) to search for versions of setuptools:
Found link file:///C:/Users/qnehd/AppData/Local/Temp/tmpq5tcirqh/setuptools-65.5.0-py3-none-any.whl, version: 65.5.0
Skipping link: wrong project name (not setuptools): file:///C:/Users/qnehd/AppData/Local/Temp/tmpq5tcirqh/pip-23.0.1-py3-none-any.whl
Local files found: C:\Users\qnehd\AppData\Local\Temp\tmpq5tcirqh\setuptools-65.5.0-py3-none-any.whl
Given no hashes to check 1 links for project 'setuptools': discarding no candidates
Processing c:\users\qnehd\appdata\local\temp\tmpq5tcirqh\setuptools-65.5.0-py3-none-any.whl
  Added setuptools from file:///C:/Users/qnehd/AppData/Local/Temp/tmpq5tcirqh/setuptools-65.5.0-py3-none-any.whl to build tracker 'C:\\Users\\qnehd\\AppData\\Local\\Temp\\pip-build-tracker-wlgbodxs'
  Removed setuptools from file:///C:/Users/qnehd/AppData/Local/Temp/tmpq5tcirqh/setuptools-65.5.0-py3-none-any.whl from build tracker 'C:\\Users\\qnehd\\AppData\\Local\\Temp\\pip-build-tracker-wlgbodxs'
0 location(s) to search for versions of pip:
Skipping link: wrong project name (not pip): file:///C:/Users/qnehd/AppData/Local/Temp/tmpq5tcirqh/setuptools-65.5.0-py3-none-any.whl
Found link file:///C:/Users/qnehd/AppData/Local/Temp/tmpq5tcirqh/pip-23.0.1-py3-none-any.whl, version: 23.0.1
Local files found: C:\Users\qnehd\AppData\Local\Temp\tmpq5tcirqh\pip-23.0.1-py3-none-any.whl
Given no hashes to check 1 links for project 'pip': discarding no candidates
Processing c:\users\qnehd\appdata\local\temp\tmpq5tcirqh\pip-23.0.1-py3-none-any.whl
  Added pip from file:///C:/Users/qnehd/AppData/Local/Temp/tmpq5tcirqh/pip-23.0.1-py3-none-any.whl to build tracker 'C:\\Users\\qnehd\\AppData\\Local\\Temp\\pip-build-tracker-wlgbodxs'
  Removed pip from file:///C:/Users/qnehd/AppData/Local/Temp/tmpq5tcirqh/pip-23.0.1-py3-none-any.whl from build tracker 'C:\\Users\\qnehd\\AppData\\Local\\Temp\\pip-build-tracker-wlgbodxs'
Created temporary directory: C:\Users\qnehd\AppData\Local\Temp\pip-unpack-ogku31px
Installing collected packages: setuptools, pip


  _find worked: 'pip\\\\_vendor\\\\distlib\\\\t64.exe' 'pip\\\\_vendor\\\\'
  _find worked: 'pip\\\\_vendor\\\\distlib\\\\t64.exe' 'pip\\\\_vendor\\\\'
Successfully installed pip setuptools
Removed build tracker: 'C:\\Users\\qnehd\\AppData\\Local\\Temp\\pip-build-tracker-wlgbodxs'

解决方案

1. 重新创建绑定Python3.9的虚拟环境

从输出可见系统全局Python为3.10,而目标版本是3.9,需明确指定版本创建虚拟环境:

# 删除现有无效虚拟环境
Remove-Item -Recurse -Force .\venv
# 使用Python3.9创建虚拟环境
py -3.9 -m venv venv
# 激活虚拟环境
.\venv\Scripts\Activate.ps1

2. 强制重新安装pip到虚拟环境

激活环境后执行以下命令,强制覆盖安装pip:

python -m ensurepip --upgrade --force-reinstall

验证安装结果:

python -m pip --version

3. 检查虚拟环境Scripts目录的PATH配置

激活环境后确认虚拟环境的Scripts目录已加入系统PATH:

$env:PATH

若未包含C:\Users\qnehd\workplace\Python\py-ui\venv\Scripts,手动添加:

$env:PATH = ".\venv\Scripts;" + $env:PATH

内容的提问来源于stack exchange,提问作者usan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 07:55:55