雷达智富

首页 > 内容 > 程序笔记 > 正文

程序笔记

Python pip 国内镜像源的配置及pip命令的使用

2024-06-29 50

前言

Python pip安装python的包经常因为网络慢而安装不成功,这种情况下可以使用pip国内镜像源,用对了pip源,就可以使用pip命令快速安装python包了。

国内镜像

清华
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 模块==版本

使用方法

特殊情况

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/

在安装过程我还遇到类似如下的错误
image-1678779988959
解决办法:

pip install -i http://pypi.douban.com/simple --trusted-host pypi.douban.com selenium==4.3.0
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 

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

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

例如升级pip

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

配制成默认的

在你的“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. 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

python中pip 安装、升级、升级指定的包

pip下载安装

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

Linux 安装pip

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

升级pip

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

pip使用p安装包详解

pip install 安装包名

  [...]
Successfully installed 包名    #安装成功

查看安装的包

pip list

pip升级包

pip install --upgrade 要升级的包名

包名 目前安装的版本号 最新版本号

pip卸载包

pip uninstall 要卸载的包名
更新于:2个月前
赞一波!4

文章评论

全部评论