pip 使用

源配置、更改

参考: https://blog.csdn.net/JineD/article/details/125090904

01.临时使用

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple package-name

02.永久更改

2.1 Linux 设置pip源

pip install --upgrade pip    # 升级 pip 到最新的版本 (>=10.0.0) 
pip config list              # 查看当前pip源

方法1:用命令配置 global.index-url、install.trusted-host

pip config set global.index-url http://mirrors.aliyun.com/pypi/simple/ 
pip config set install.trusted-host mirrors.aliyun.com
pip install update

方法2:也可以通过配置文件的形式更换源

mkdir ~/.pip
vi ~/.pip/pip.conf
# 新增以下内容:
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com
# 保存后退出
pip install update

2.2 windows 设置pip源

在资源管理器中,打开%HOMEPATH%,然后在该目录新建一个名为pip的文件夹,在pip文件夹中创建一个pip.ini文件,用记事本写入配置如下:
即在目录为C:\Users\你的帐户名\pip,pip.ini中添加以下内容

[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com

pip 国内镜像源

来源 URL地址
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣 http://pypi.douban.com/simple
Python官方 https://pypi.python.org/simple/
v2ex http://pypi.v2ex.com/simple/
××× http://pypi.mirrors.opencas.cn/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/

问题汇总

01.pandas 安装失败

现象:使用命令 "pip install pandas" 出现错误

pip install pandas
...
ERROR: Could not build wheels for pandas which use PEP 517 and cannot be installed directly

原因:python与pandas版本不兼容
处理:试试选择特定版本

pip install pandas==1.1.5

02. 被警告为不信任源的处理

现象:执行pip list 命令被警告

WARNING: The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host mirrors.aliyun.com'.
WARNING: There was an error checking the latest version of pip.

原因:被警告为不信任源,应该也可用忽略
处理:设置信任这个镜像网址

pip install pymssql -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

posted on 2022-11-04 22:38  これから  阅读(18)  评论(0)    收藏  举报

导航