Python包安装失败最主要原因是默认安装源为国外服务器,安装速度慢,将安装源指向国内服务器是常用解决方案;另一个中要原因是安装包与当前Python版本不匹配,寻根溯源进行匹配安装是该情况的解决方案。
通常情况下,设置如下常用清华源的命令即可(使用管理员打开Anaconda Prompt):
- conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- # 设置搜索时显示通道地址
- conda config --set show_channel_urls yes
中科大源:
- conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
- conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
- conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
- conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
- conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
- conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
- # 设置搜索时显示通道地址
- conda config --set show_channel_urls yes
如需更复杂的源设置,可以直接通过修改当前源设置文件快速批量修改。conda当前的源设置在$HOME/.condarc或者C:\users\[username]\.condarc文件中,可通过文本编辑器直接进行如下修改(直接拷贝如下配置即可)。
- channels:
- - defaults
- show_channel_urls: true
- default_channels:
- -
- -
- -
- custom_channels:
- conda-forge:
- msys2:
- bioconda:
- menpo:
- pytorch:
- pytorch-lts:
虽然也可以通过配置文件永久安装,我们更推荐快速命令安装:
- """
- 1、采用国内源,加速下载模块的速度
- 2、常用pip源:
- -- 清华: https://pypi.tuna.tsinghua.edu.cn/simple/
- -- 中科大: https://pypi.mirrors.ustc.edu.cn/simple/
- -- 阿里: https://mirrors.aliyun.com/pypi/simple/
- -- 豆瓣: https://pypi.douban.com/simple/
- 3、加速安装的命令:
- -- >: pip install -i https://pypi.douban.com/simple 模块名
- """
电脑安装多个python版本,安装包也已经安装,但不能正确将安装包与python进行匹配。可使用python --version以及conda list等命令查看当前conda环境是否安装了响应本,如未安装,切换其它虚拟环境进行尝试。
多次尝试使用命令进行安装,最终痘失败,可能使python版本过旧或者过新而未有相应版本python支持,此种情况通常可以使用再次安装支持该包的某一python版本(常使用可选最新稳定版)。