【Python】设置pip源为国内源及简单操作

一、pip国内源镜像:

阿里云:http://mirrors.aliyun.com/pypi/simple/
中国科技大学:https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban):http://pypi.douban.com/simple/
清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学:http://pypi.mirrors.ustc.edu.cn/simple/

二、修改源方法:

1.临时修改
可以在使用pip的时候在后面加上-index参数,指定pip源:

pip install --index https://pypi.tuna.tsinghua.edu.cn/simple requests

2.配置文件
Linux
①修改 ~/.pip/pip.conf (没有就创建一个), 内容如下:

[root@localhost .pip]# cat ~/.pip/pip.conf 
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

②使用:

[root@localhost .pip]# pip install xlwt
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting xlwt
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/44/48/def306413b25c3d01753603b1a222a011b8621aed27cd7f89cbc27e6b0f4/xlwt-1.3.0-py2.py3-none-any.whl (99 kB)
     |████████████████████████████████| 99 kB 735 kB/s 
Installing collected packages: xlwt
Successfully installed xlwt-1.3.0

Windows:
①在我的电脑上的地址栏输入:%appdata% ,然后回车;
②在里面新建一个名为 pip 的文件夹;
③在 pip 文件夹里面新建一个文件叫做 pip.ini ,内容写如下即可。实际就是这么一个文件 : %appdata%pippip.ini。
文件内容如下:

[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn

④使用pyreadline库,可实现Windows中python的tab键补全,安装如下:

C:Usersannie.wu>pip install pyreadline
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pyreadline
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bc/7c/d724ef1ec3ab2125f38a1d53285745445ec4a8f19b9bb0761b4064316679/pyreadline-2.1.zip (109kB)
     |████████████████████████████████| 112kB 1.1MB/s
Installing collected packages: pyreadline
  Running setup.py install for pyreadline ... done
Successfully installed pyreadline-2.1
WARNING: You are using pip version 19.2.3, however version 20.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

3.简单操作
①接下来,用 pip 试试安装各种库:

pip install xlwt
pip install xlrd
pip install six
pip install requests
pip install oauthlib
pip install requests_oauthlib

②其他使用示例

升级pip
python -m pip install -U pip
安装相关库
python -m pip install psutil
卸载相关库
python -m pip uninstall psutil
查看已安装的库
python -m pip freeze
原文地址:https://www.cnblogs.com/wucaiyun1/p/12880825.html