2022年 11月 4日

Python pip 国内镜像大全及使用办法

Python pip 国内镜像大全及使用办法

一、国内镜像

清华
https://pypi.tuna.tsinghua.edu.cn/simple
豆瓣
pip install -i http://pypi.douban.com/simple --trusted-host pypi.douban.com '模块版本'
阿里云
pip install -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com '模块版本'
中国科学技术大学
pip install -i http://pypi.mirrors.ustc.edu.cn/simple/ --trusted-host pypi.mirrors.ustc.edu.cn '模块版本'
华中理工大学
pip install -i http://pypi.hustunique.com/simple/ --trusted-host pypi.hustunique.com '模块版本'
山东理工大学
pip install -i http://pypi.sdutlinux.org/simple/ --trusted-host pypi.sdutlinux.org '模块==版本'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

二、使用办法

特殊情况

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl
.c:1124)'))': /simple/xlwt/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl
.c:1124)'))': /simple/xlwt/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl
.c:1124)'))': /simple/xlwt/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl
.c:1124)'))': /simple/xlwt/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl
.c:1124)'))': /simple/xlwt/

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

在安装过程我还遇到类似如下的错误
在这里插入图片描述
解决方案

pip install -i http://pypi.douban.com/simple --trusted-host pypi.douban.com selenium==4.3.0
  • 1
python.exe -m pip install --upgrade pip
# pip install Bio -i https://pypi.douban.com/simple/
pip install Bio -i http://pypi.douban.com/simple --trusted-host pypi.douban.com 
  • 1
  • 2
  • 3

1、临时使用,添加“-i”或“–index”参数

pip install django==1.11.25 -i https://pypi.douban.com/simple/
  • 1

例如升级pip

python -m pip install --upgrade pip -i https://pypi.douban.com/simple/
  • 1

2、配制成默认的

在你的“C:\Users\你的用户名\”目录下创建“pip”目录,“pip”目录下创建“pip.ini”文件(注意:以UTF-8 无BOM格式编码);
“pip.ini”文件内容:

[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
  • 1
  • 2
  • 3
  • 4

3、注意:

1、trusted-host 选项为了避免麻烦是必须的,否则使用的时候会提示不受信任,或者添加“–trusted-host=mirrors.aliyun.com”选项;
2、有网页提示需要创建或修改配置文件(linux的文件在~/.pip/pip.conf,windows在%HOMEPATH%\pip\pip.ini),至少Windows7下“%HOMEPATH%\pip\pip.ini”这个目录是不起作用的。

三、在线下载模块离线安装包以及依赖包

# 在线下载离线安装包以及依赖
pip download 你的包名 -d "下载的路径(windows下双引号来表示文件夹)"

# 离线自动安装安装包以及依赖
conda create -n CasRel python=3.6.5
pip install -r requirements.txt --no-index --find-links=./pip_pkgs
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

四、python中pip 安装、升级、升级固定的包

1、pip下载安装
下载 进入https://pypi.python.org/pypi/pip,下载 .tar.gz压缩包

2、Linux 安装pip

tar -xzvf pip-1.5.4.tar.gz      解压
cd pip-1.5.4                    进入解压文件
python setup.py install         安装
  • 1
  • 2
  • 3

3、升级pip

python -m pip install --upgrade pip
python -m pip install --upgrade pip -i https://pypi.douban.com/simple/
  • 1
  • 2

4、pip使用p安装包详解

pip install 安装包名

  [...]
Successfully installed 包名    #安装成功
2.3 pip检查哪些包需要更新
  • 1
  • 2
  • 3
  • 4
  • 5

5、查看安装的包

pip list
  • 1

6、 pip升级包

pip install --upgrade 要升级的包名

  包名  目前安装的版本号    最新版本号
  • 1
  • 2
  • 3

7、 pip卸载包

pip uninstall 要卸载的包名
  • 1