iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Python中Pip的安装操作
  • 593
分享到

Python中Pip的安装操作

pythonpiplinux 2023-09-14 17:09:06 593人浏览 泡泡鱼

Python 官方文档:入门教程 => 点击学习

摘要

get-pip.py安装 Python有两个著名的包管理工具easy_install和pip。在Python2.7的安装包中,easy_install是默认安装的,而pip需要我们手动

Python有两个著名的包管理工具easy_install和pip。在Python2.7的安装包中,easy_install是默认安装的,而pip需要我们手动安装。随着Python版本的提高,easy_install已经逐渐被淘汰,但是一些比较老的第三方库,在现在仍然只能通过easy_install进行安装。目前,pip已经成为主流的安装工具,自Python2 >=2.7.9或者python3.4以后默认都安装有pip。

如果很不巧,你的python版本下恰好没有pip这个工具,怎么办呢?解决办法很多!

  1. 使用easy_install安装: 各种进入到easy_install脚本的目录下,然后运行easy_inatall pip
  2. 使用get-pip.py安装: 在下面的url下载get-pip.py脚本 curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py 然后运行:Python get-pip.py 这个脚本会同时安装setuptools和wheel工具。
  3. linux下使用包管理工具安装pip: 例如,ubuntu下:sudo apt-get install python-pip。Fedora系下:sudo yum install python-pip
  4. windows下安装pip: 在C:\python27\scirpts下运行easy_install pip进行安装。

刚安装完毕的pip可能需要先升级一下自身: 在Linux或masOS中:pip install -U pip 在windows中:python -m pip install -U pip

get-pip.py安装

以方法2. 使用get-pip.py安装,为例

新建一个文本文档,起名为get-pip,后缀名该为.py

打开网址Https://bootstrap.pypa.io/get-pip.py,复制所有文字到我们新建的文件get-pip.py中

在这里插入图片描述
源代码中 DATA = b"“” 乱码 “”",,,DATA 后面注释的乱码有3万多行,我直接给删了,不影响

下面是我实际可运行的代码

#!/usr/bin/env python## Hi There!## You may be wondering what this giant blob of binary data here is, you might# even be worried that we're up to something nefarious (Good for you for being# paranoid!). This is a base85 encoding of a zip file, this zip file contains# an entire copy of pip (version 22.3.1).## Pip is a thing that installs packages, pip itself is a package that someone# might want to install, especially if they're looking to run this get-pip.py# script. Pip has a lot of code to deal with the security of installing# packages, various edge cases on various platfORMs, and other such sort of# "tribal knowledge" that has been encoded in its code base. Because of this# we basically include an entire copy of pip inside this blob. We do this# because the alternatives are attempt to implement a "minipip" that probably# doesn't do things correctly and has weird edge cases, or compress pip itself# down into a single file.## If you're wondering how this is created, it is generated using# `scripts/generate.py` in https://GitHub.com/pypa/get-pip.import systhis_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)import os.pathimport pkgutilimport shutilimport tempfileimport argparseimport importlibfrom base64 import b85decodedef include_setuptools(args):    """    Install setuptools only if absent and not excluded.    """    cli = not args.no_setuptools    env = not os.environ.get("PIP_NO_SETUPTOOLS")    absent = not importlib.util.find_spec("setuptools")    return cli and env and absentdef include_wheel(args):    """    Install wheel only if absent and not excluded.    """    cli = not args.no_wheel    env = not os.environ.get("PIP_NO_WHEEL")    absent = not importlib.util.find_spec("wheel")    return cli and env and absentdef determine_pip_install_arguments():    pre_parser = argparse.ArgumentParser()    pre_parser.add_argument("--no-setuptools", action="store_true")    pre_parser.add_argument("--no-wheel", action="store_true")    pre, args = pre_parser.parse_known_args()    args.append("pip")    if include_setuptools(pre):        args.append("setuptools")    if include_wheel(pre):        args.append("wheel")    return ["install", "--upgrade", "--force-reinstall"] + argsdef monkeypatch_for_cert(tmpdir):    """Patches `pip install` to provide default certificate with the lowest priority.    This ensures that the bundled certificates are used unless the user specifies a    custom cert via any of pip's option passing mechanisms (config, env-var, CLI).    A monkeypatch is the easiest way to achieve this, without messing too much with    the rest of pip's internals.    """    from pip._internal.commands.install import InstallCommand    # We want to be using the internal certificates.    cert_path = os.path.join(tmpdir, "cacert.pem")    with open(cert_path, "wb") as cert:        cert.write(pkgutil.get_data("pip._vendor.certifi", "cacert.pem"))    install_parse_args = InstallCommand.parse_args    def cert_parse_args(self, args):        if not self.parser.get_default_values().cert:            # There are no user provided cert -- force use of bundled cert            self.parser.defaults["cert"] = cert_path  # calculated above        return install_parse_args(self, args)    InstallCommand.parse_args = cert_parse_argsdef bootstrap(tmpdir):    monkeypatch_for_cert(tmpdir)    # Execute the included pip and use it to install the latest pip and    # setuptools from PyPI    from pip._internal.cli.main import main as pip_entry_point    args = determine_pip_install_arguments()    sys.exit(pip_entry_point(args))def main():    tmpdir = None    try:        # Create a temporary working directory        tmpdir = tempfile.mkdtemp()        # Unpack the zipfile into the temporary directory        pip_zip = os.path.join(tmpdir, "pip.zip")        with open(pip_zip, "wb") as fp:            fp.write(b85decode(DATA.replace(b"\n", b"")))        # Add the zipfile to sys.path so that we can import it        sys.path.insert(0, pip_zip)        # Run the bootstrap        bootstrap(tmpdir=tmpdir)    finally:        # Clean up our temporary working directory        if tmpdir:            shutil.rmtree(tmpdir, ignore_errors=True) DATA = b"""""" if __name__ == "__main__":    main()

代码开头的一段说明文字

你可能想知道这一大块二进制数据是什么甚至担心我们在做一些邪恶的事情(对你来说是件好事偏执!)这是一个base85编码的zip文件,这个zip文件包含pip的完整副本(版本22.3.1)。pip是一个安装包的东西,pip本身就是一个包可能想要安装,特别是如果他们想要运行这个get-pip.py脚本。Pip有很多代码来处理安装的安全性包,各种平台上的各种边缘情况,等等“部落知识”已被编码在其代码库中。正因为如此我们基本上在这个blob中包含了PIP的完整副本。我们这样做因为替代方案是试图实现一个“小程序”,可能不能正确地做事情,并且有奇怪的边缘情况,或者压缩pip本身分解成一个文件。如果你想知道这是如何创建的,它是使用https://github.com/pypa/get-pip中的' scripts/generate.py '

打开cmd,找到get-pip.py文件的路径 ,然后输入python get-pip.py,敲回车就开始安装

在这里插入图片描述
4、安装完成后,可以在cmd中输入pip list测试一下,显示如下信息就是安装成功了。
在这里插入图片描述
5、如果没有显示,则需要回到python的安装目录,将scripts目录加到path环境变量中,然后重启cmd
在这里插入图片描述

来源地址:https://blog.csdn.net/m0_51233386/article/details/128465906

--结束END--

本文标题: Python中Pip的安装操作

本文链接: https://www.lsjlt.com/news/407607.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Python中Pip的安装操作
    get-pip.py安装 Python有两个著名的包管理工具easy_install和pip。在Python2.7的安装包中,easy_install是默认安装的,而pip需要我们手动...
    99+
    2023-09-14
    python pip linux
  • Python的pip安装
    我安装的是Python3,在安装目录下有一个libexec目录,里面有一个pip包 进入pip目录 cd libexec/pip/ 安装pip python3 setup.py install 查看pip版本 pip --ver...
    99+
    2023-01-31
    Python pip
  • Python 2.7中安装pip
    Python 2.7中安装pip的方法及步骤(引用别人的) levi 编辑于  2022-04-12 本文主要介绍Python2(Python 2.7)中,下载安装setup-tools和pip的方法及步骤。 1、安装setup-tools...
    99+
    2023-09-27
    linux 运维 服务器
  • CentOS中安装Python-PIP
     首先要安装 Setuptools wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg sh setuptools-0.6c11...
    99+
    2023-01-31
    CentOS Python PIP
  • Python:安装pip
    python想要安装很多工具包都要使用到pip 这时候如何安装pip就显得很重要了,当然前提是安装了Python,并且配置了环境变量 1.pip的安装网站 https://pypi.org/project/pip/ 选择网站的Down...
    99+
    2023-01-31
    Python pip
  • [python] 安装pip
    1.下载pip wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb" --no...
    99+
    2023-01-31
    python pip
  • Python 安装setuptools和pip工具操作方法(必看)
    setuptools模块和pip模块是python进行第三方库扩展的极重要工具,例如我们在需要安装一些爬虫或者数据分析的包时就可以使用pip install命令来直接安装这些包了,因此pip工具一定要提前安...
    99+
    2022-06-04
    必看 操作方法 工具
  • python中如何安装pip
    今天就跟大家聊聊有关python中如何安装pip,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。python主要应用领域有哪些1、云计算,典型应用OpenStack。2、WEB前端开发...
    99+
    2023-06-14
  • pip安装MySQL-python
    <br> 首先安装pip yum install python-setuptools python-setuptools-devel easy_install pip 然后升级pip,安装setuptools合适的版本 yum...
    99+
    2023-01-31
    pip MySQL python
  • pip安装opencv-python
    文章目录 前言一、基本概念二、操作步骤1.删除旧版本2.pip升级3.opencv-python安装 总结 前言 OpenCV的全称是Open Source Computer V...
    99+
    2023-09-07
    python opencv pip
  • python的pip怎么安装
    要安装Python的pip,可以按照以下步骤进行:1. 首先,确保已经正确安装了Python。可以在命令行输入`python --v...
    99+
    2023-09-27
    python
  • centos7下安装Python的pip
    root用户使用yum install -y python-pip 时会报如下错误:No package python-pip availableError:Nothing to do解决方法如下:  首先安装epel扩展源:  yum -...
    99+
    2023-01-31
    Python pip
  • 怎么安装Python的pip
    本篇内容主要讲解“怎么安装Python的pip”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么安装Python的pip”吧!安装pip那么,如果很不巧,你的Python版本下恰好没有pip这个...
    99+
    2023-06-02
  • python安装pip的命令
    python安装pip的方法有“使用 get-pip.py 脚本“和”使用操作系统的包管理器“两种方法:1、打开一个浏览器下载”get-pip.py“脚本文件,打开命令行终端并导航到文件所在目录,运行”python get-pip.py“命...
    99+
    2023-12-19
    python pip安装命令 pip
  • python安装及pip django安
    #############################为了跟方便的安装,使用集成包Anaconda下载Anaconda到当前目录 sh Anaconda3-5.0.1-Linux-x86_64.shln -s /root/anacond...
    99+
    2023-01-31
    python pip django
  • 如何在Python中安装pip
    如何在Python中安装pip 在Python中,pip是一个非常常用的软件包管理工具,它允许我们方便地安装、升级和管理第三方库。如果你的Python环境中没有安装pip,那么你可以按照以下步骤来安装...
    99+
    2023-10-21
    python pip 开发语言 Python
  • Python安装升级pip
    #!/usr/bin/env python #coding:utf-8 import os import tarfile setuptools_url='https://pypi.python.org/packages/source/s/...
    99+
    2023-01-31
    Python pip
  • python 安装pip和Django
    下载安装脚本wget https://bootstrap.pypa.io/get-pip.py  python3 get-pip.py安装完成后安装djangopython3 -m pip install Django==1.9.4这就安装...
    99+
    2023-01-31
    python pip Django
  • Python pip怎么安装
    要安装Python包或模块,你可以使用pip命令。以下是安装Python包的步骤:1. 确保你已经安装了Python和pip。在终端...
    99+
    2023-09-22
    python
  • python怎么安装pip
    python安装pip的步骤:1、打开命令行或终端;2、输入“python -m ensurepip --default-pip”命令以安装pip,确保pip被安装为Python的默认包管理工具;3、可以输入“pip --version”命...
    99+
    2023-12-09
    python pip
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作