持续总结python pip遇到过的坑。
1、pip镜像源
#阿里镜像-临时
pip install xxx -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
#豆瓣镜像-临时
pip install xxx -i https://pypi.douban.com/simple/
#永久
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
2、conda镜像源
首先输入:
conda config --set show_channel_urls yes
在~/.condarc文件输入如下内容(vi ~/.condarc)
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
如果需要移除镜像源,直接输入:
conda config --remove channels
3、安装pycrypto
Python3中安装pycrypto错误的最简解决方案,不用安装xG的C编译器,直接用下面命令安装:
pip install pycryptodome
Python3中安装pycrypto错误的最简解决方案,不用安装xG的C编译器_hirbale的博客-CSDN博客
4、 cl.exe failed
pip 安装模块时 cl.exe failed 可能的解决办法
pip 安装模块时 cl.exe failed 可能的解决办法 - 哔哩哔哩
5、安装到指定目录
pip install xxx -t dest_dir
6、 pip install安装错误
pip install安装时可能出现如下错误:
UnicodeDecodeError: 'gbk' codec can't decode byte 0x98 in position 1027: illegal multibyte sequence
解决方法:找到python安装目录下的Lib\configparser.py文件,将其中的第695行进行如下更改:
with open(filename, encoding=encoding) as fp:
self._read(fp, filename)
#改为:
with open(filename, encoding='utf-8') as fp:
self._read(fp, filename)
7、windows pip install 错误
ERROR: Could not build wheels for argon2-cffi which use PEP 517 and cannot be installed directly
fatal error C1083: 无法打开包括文件: “io.h”: No such file or directory
出现这些问题,很有可能是pip自身环境出错了,建议卸载并重新安装pip。
(1)卸载pip:python -m pip uninstall pip
(2)cmd输入:py -m ensurepip --upgrade
(3)get-pip.py下载:https://download.csdn.net/download/suiyingy/85506671或https://bootstrap.pypa.io/get-pip.py
(4)cmd输入:py get-pip.py
8 pip卸载包错误
ERROR: Cannot uninstall [pacakage]. It is a distutils installed project…
解决方案:先使用pip install --ignore-installed [package]后再卸载或者重装