暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Python pip 的安装

生有可恋 2022-08-19
3193

默认在安装Python时会安装pip,pip的默认安装位置为<python-home>/Scripts。如果环境中没有pip,此时需要独立进行安装。


安装方法有两种:

  • ensurepip

  • get-pip.py


其中ensurepip是Python3.4之后默认加入的,目前已加入到标准库中了。当使用的Python版本为3.4以上时,可以直接使用ensurepip安装pip。安装命令为:

    python -m ensurepip --upgrade


    另一种方法是使用脚本安装,其中脚本会自动检测当前所使用的Python版本,从而执行相应的安装步骤。脚本下载地址为:

    • https://bootstrap.pypa.io/get-pip.py


    将get-pip.py下载下来的,执行脚本:

      python get-pip.py

      实际上get-pip.py的内容也是有版本要求的,从代码可以知道,当前get-pip支持的最小版本是3.7,其它版本需要下载相应具体的get-pip.py

        import sys


        this_python = sys.version_info[:2]
        min_version = (3, 7)
        if this_python < min_version:
        message_parts = [
        "This script does not work on Python {}.{}".format(*this_python),
        "The minimum supported Python version is {}.{}.".format(*min_version),
        "Please use https://bootstrap.pypa.io/pip/{}.{}/get-pip.py instead.".format(*this_python),
        ]
        print("ERROR: " + " ".join(message_parts))
        sys.exit(1)

        根据提示信息,我们到相应网站去查看,可以看到各大的版本的get-pip已经按目录分好了:

        • https://bootstrap.pypa.io/pip/

        Pyhton3.7 以上,使用get-pip.py,其它版本使用x.x目录下的get-pip.py,链接分别为:

        • https://bootstrap.pypa.io/pip/2.6/get-pip.py

        • https://bootstrap.pypa.io/pip/2.7/get-pip.py

        • https://bootstrap.pypa.io/pip/3.2/get-pip.py

        • https://bootstrap.pypa.io/pip/3.3/get-pip.py

        • https://bootstrap.pypa.io/pip/3.4/get-pip.py

        • https://bootstrap.pypa.io/pip/3.5/get-pip.py

        • https://bootstrap.pypa.io/pip/3.6/get-pip.py

        • https://bootstrap.pypa.io/pip/get-pip.py      (>=3.7)


        安装完成后试着执行python -m pip 看能否执行,能执行说明 pip 安装成功。在 Linux 上使用 which pip 查找 pip 的安装位置,而在 Windows 上则使用 where pip 命令查找 pip 安装的位置。



        全文完。


        如果转发本文,文末务必注明:“转自微信公众号:生有可恋”。


        文章转载自生有可恋,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

        评论