Pip 没有在虚拟环境中安装包
Pip isn't installing packages in virtual environment
在 windows,python 3.9.5.
我使用 python -m venv env
创建了一个虚拟环境。我激活它,没有问题。
我验证在使用 pip
和 python
时我使用的是我的虚拟环境,这里没有问题。
我输入 python -m pip install wheel
。因为我还在使用 venv,pip 应该尝试在 .\env\Lib\site-packages
中安装,但 pip 正在尝试在 C:\Program Files\Python39\Lib\site-packages
.
中安装它
使用 pip install wheel
时得到相同的结果
谁能解释一下哪里出了问题,我应该怎么做才能解决这个问题?
命令和输出:
python -m venv env
--> 已创建文件夹
.\env\Scripts\activate
--> 虚拟环境激活
where python
--> C:\Users\user\Documents\env\Scripts\python.exe
和 C:\Program Files\Python39\python.exe
pip -V
--> pip 21.1.1 from c:\users\user\documents\env\lib\site-packages\pip (python 3.9)
python -m pip install wheel
-->
Collecting wheel
Using cached wheel-0.37.0-py2.py3-none-any.whl (35 kB)
Installing collected packages: wheel
Successfully installed wheel-0.37.0
WARNING: Target directory C:\Program Files\Python39\Lib\site-packages\wheel already exists. Specify --upgrade to force replacement.
WARNING: Target directory C:\Program Files\Python39\Lib\site-packages\wheel-0.37.0.dist-info already exists. Specify --upgrade to force replacement.
WARNING: Target directory C:\Program Files\Python39\Lib\site-packages\bin already exists. Specify --upgrade to force replacement.
我们可以使用-t
参数
强制pip在我们想要的地方安装包
示例:
- 转到
env\Lib\site-packages
- 使用
pip install -t . package
或python -m pip install -t . package
之后它应该可以正常工作
在 windows,python 3.9.5.
我使用 python -m venv env
创建了一个虚拟环境。我激活它,没有问题。
我验证在使用 pip
和 python
时我使用的是我的虚拟环境,这里没有问题。
我输入 python -m pip install wheel
。因为我还在使用 venv,pip 应该尝试在 .\env\Lib\site-packages
中安装,但 pip 正在尝试在 C:\Program Files\Python39\Lib\site-packages
.
中安装它
使用 pip install wheel
谁能解释一下哪里出了问题,我应该怎么做才能解决这个问题?
命令和输出:
python -m venv env
--> 已创建文件夹
.\env\Scripts\activate
--> 虚拟环境激活
where python
--> C:\Users\user\Documents\env\Scripts\python.exe
和 C:\Program Files\Python39\python.exe
pip -V
--> pip 21.1.1 from c:\users\user\documents\env\lib\site-packages\pip (python 3.9)
python -m pip install wheel
-->
Collecting wheel
Using cached wheel-0.37.0-py2.py3-none-any.whl (35 kB)
Installing collected packages: wheel
Successfully installed wheel-0.37.0WARNING: Target directory C:\Program Files\Python39\Lib\site-packages\wheel already exists. Specify --upgrade to force replacement.
WARNING: Target directory C:\Program Files\Python39\Lib\site-packages\wheel-0.37.0.dist-info already exists. Specify --upgrade to force replacement.
WARNING: Target directory C:\Program Files\Python39\Lib\site-packages\bin already exists. Specify --upgrade to force replacement.
我们可以使用-t
参数
示例:
- 转到
env\Lib\site-packages
- 使用
pip install -t . package
或python -m pip install -t . package
之后它应该可以正常工作