《pip 安装与国内镜像源配置》
1. 安装 pip
Debian / Ubuntu
apt install python3-pip
pip3 install --upgrade pip
CentOS
方法一:使用官方安装脚本
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
方法二:启用 epel 仓库后安装
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
sudo yum install ./epel-release-latest-*.noarch.rpm
方法三:直接 yum
yum install epel-release
yum install python-pip
2. 配置国内镜像源
使用清华 PyPI 镜像:
# 临时使用
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
# 全局默认使用
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
或编辑 ~/.pip/pip.conf:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn
3. 常见问题
3.1 python setup.py egg_info failed with error code 1
升级 setuptools:
pip install --upgrade setuptools
3.2 Cannot uninstall ‘numpy’
属于 distutils 安装的项目,无法准确判断文件归属:
pip install --ignore-installed numpy
3.3 Python.h: No such file or directory
缺少编译所需头文件:
apt-get install python-dev
3.4 ImportError: cannot import name IncompleteRead
卸载系统 pip 后重新通过 easy_install 安装:
apt-get remove python-pip
easy_install pip
阅读 —
·
全站 —