venv中的pip版本不匹配 [英] pip version mismatch in venv

查看:288
本文介绍了venv中的pip版本不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对虚拟Python环境的工作方式感到困惑(Python 3.6,使用venv).我设置了venv,并在命令行中将其激活.我希望从那时起我所做的一切都使用虚拟环境中的python和pip命令(因为这些目录在激活时已添加到PATH中).

I am confused about how virtual Python environments work (Python 3.6, using venv). I set up my venv, and activated it in the command line. I would expect that everything I do from then on out uses the python and pip commands from the virtual environment (as these directories are added to PATH upon activation).

问题是,当我在venv中运行pip --version时,它将返回pip 10.0.1.但是,当我尝试使用python -m pip install --upgrade pip对其进行升级时,会得到Requirement already up-to-date

The thing is, that when I run pip --version in my venv, it returns pip 10.0.1. But when I try to upgrade it with python -m pip install --upgrade pip, I get Requirement already up-to-date

(venv) PS C:\Python\files\myproj> pip --version
> pip 10.0.1 from c:\python\files\myproj\venv\lib\site-packages\pip-10.0.1-py3.6.egg\pip (python 3.6)
(venv) PS C:\Python\files\myproj> python -m pip install --upgrade pip
> Requirement already up-to-date: pip in c:\python\files\myproj\venv\lib\site-packages (18.0)

那是怎么回事?为什么不以与python相同的pip为目标的命令行命令?以及如何补救呢?

So what's going on? Why isn't the command line command targeting the same pip as python is? And how to remedy this?

推荐答案

pip仍然指向全局变量,即使在venv中也是如此.但是,python不会使用venv.

pip still points to the global one, even when in an venv. python, however, does not and uses the venv.

这意味着当您运行pip --version时,将获得全局pip版本.当您运行python -m pip install --upgrade pip时,您使用的是venv版本的python,它显然已经具有最新的pip.要确认这一点,可以运行python -m pip --version,并且应该获得最新版本作为输出.

This means that when you run pip --version, you get your global pip version. when you run python -m pip install --upgrade pip, you're using the venv version of python, which apparently already has the newest pip. To confirm this, you can run python -m pip --version and you should get the latest version as an output.

这篇关于venv中的pip版本不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆