pip的常用操作命令

 

 1. 忽略已安装的库(以llvmlite为例)

pip install xxx --ignore-installed llvmlite

2. 错误 -  AttributeError: 'int' object has no attribute 'endswith'

解决方案:

常见原因因为使用的pip为pip2,可以使用 pip -V 查看pip版本,必要时使用 pip3

3. 错误 - ImportError: cannot import name 'sysconfig'

 解决方案:

sudo gedit /etc/apt/sources.list

# 追加源
deb http://cn.archive.ubuntu.com/ubuntu bionic main multiverse restricted universe
deb http://cn.archive.ubuntu.com/ubuntu bionic-updates main multiverse restricted universe
deb http://cn.archive.ubuntu.com/ubuntu bionic-security main multiverse restricted universe
deb http://cn.archive.ubuntu.com/ubuntu bionic-proposed main multiverse restricted universe

# 保存后运行
sudo apt-get update
sudo apt-get install python3-pip

4. 错误 - TypeError: expected str, bytes or os.PathLike object, not int

 解决方案:

# 临时方案:安装的时候,设置PIP_NO_CACHE_DIR为off,即不使用缓存
# 以opencv-python库为例
PIP_NO_CACHE_DIR=off pip3 install opencv-python
或
pip install opencv-python --no-cache-dir

# 一劳永逸
pip install --upgrade pip --no-cache-dir    # 更新pip