Pip更新及Python数据分析库的安装

本文介绍了如何在Python环境中遇到pip版本低或库安装问题时,通过使用国内的镜像源(如清华、豆瓣、阿里云等)来加速并解决更新和安装过程。详细步骤包括设置镜像源、利用镜像源安装与更新Numpy、Matplotlib等库,并展示了使用pip管理已安装包的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  今天换了一台电脑在调用Numpy库的时候,发现这个库没有装,于是准备用pip进行安装,但是呢,pip库版本太低需要更新,那么安装正常办法就是通过python -m install pip -upgrade pip,结果却不尽人意中间总是会报错,通过查阅资料发现在更新的也是可以利用镜像网站来进行更新安装的,如下:

I.镜像源

  1. 清华:https://pypi.tuna.tsinghua.edu.cn/simple
  2. 豆瓣:http://pypi.douban.com/simple/
  3. 阿里云:http://mirrors.aliyun.com/simple/
  4. 中科大: https://pypi.mirrors.ustc.edu.cn/simple/
  5. 华中科技:http://pypi.mirrors.hust.edu.cn/simple/
  6. HongKong: http://mirror.vpshosting.com.hk/
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

II.利用镜像源进行安装

利用清华镜像进行安装:
  安装:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
  或者:pip install some-package -i https://pypi.tuna.tsinghua.edu.cn/simple(-i 指定镜像地址)
  更新:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U(/-upgrade)
  或者:pip install -U pip -i https://pypi.tuna.tsinghua.edu.cn/simple

同样利用其它镜像源也可以进行安装:
  土豆源python -m pip install --upgrade pip -i https://pypi.douban.com/simple
  … …
  … …

III.安装Numpy库和Matplotlib库

  利用上面的命令便可,如(python3):
  Numpy库:pip3 install Numpy -i https://pypi.tuna.tsinghua.edu.cn/simple
   或者:pip3 install numpy scipy matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
  Matplotlib库:pip3 install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple

最后利用pip listpip show some_package进行查看是否安装成功即可。

NiKoJJ@LAPTOP-AJQRBC0C MINGW64 ~/Desktop
$ pip list
Package         Version
--------------- ---------
certifi         2020.6.20
cycler          0.10.0
kiwisolver      1.2.0
matplotlib      3.3.2
numpy           1.19.2
Pillow          8.0.1
pip             20.2.4
pyparsing       2.4.7
python-dateutil 2.8.1
scipy           1.5.3
setuptools      47.1.0
six             1.15.0
you-get         0.4.1456

NiKoJJ@LAPTOP-AJQRBC0C MINGW64 ~/Desktop
$ pip show numpy
Name: numpy
Version: 1.19.2
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: None
License: BSD
Location: d:\python3.8\lib\site-packages
Requires:
Required-by: scipy, matplotlib

IV.Pip使用

1.安装/卸载some-package

pip install/uninstall some-package 
or
pip install/uninstall some-package -i 镜像url

2.显示已安装的package

pip list
or
pip show some-package

3.查看可更新的package

pip list --outdated

****\\\\\\result\\\\\\\****
Package    Version Latest Type
---------- ------- ------ -----
setuptools 47.1.0  50.3.2 wheel

4.更新package

pip install -U setuptools (the package you want to install)
or
pip install --upgrade setuptools (the package you want to install)

********\\\\\\\\\\\\\\\\\\\\\\\\\\result\\\\\\\\\\\\\\\\\\\\\\\********
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting setuptools
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6d/38/c21ef5034684ffc0412deefbb07d66678332290c14bb5269c85145fbd55e/setuptools-50.3.2py3-none-any.whl (785 kB)
Installing collected packages: setuptools
  Attempting uninstall: setuptools
    Found existing installation: setuptools 47.1.0
    Uninstalling setuptools-47.1.0:
      Successfully uninstalled setuptools-47.1.0
Successfully installed setuptools-50.3.2

V.Ending… …

          最后我们也是成功将问题给解决了,希望这篇文章可以帮助到你呢!
在这里插入图片描述

更多内容请访问我的博客小站,链接:NiKoJJ’s Blog
同时欢迎关注微信公众号,获取更多有趣内容!
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值