• python扩展包安装失败解决方案


    一、源服务器管理

    Python包安装失败最主要原因是默认安装源为国外服务器,安装速度慢将安装源指向国内服务器是常用解决方案;另一个中要原因是安装包与当前Python版本不匹配,寻根溯源进行匹配安装是该情况的解决方案。

    1. Anaconda源管理

            通常情况下,设置如下常用清华源的命令即可(使用管理员打开Anaconda Prompt):

    1. conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
    2. conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
    3. # 设置搜索时显示通道地址
    4. conda config --set show_channel_urls yes

            中科大源:

    1. conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
    2. conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
    3. conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
    4. conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
    5. conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
    6. conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
    7. # 设置搜索时显示通道地址
    8. conda config --set show_channel_urls yes

            如需更复杂的源设置,可以直接通过修改当前源设置文件快速批量修改。conda当前的源设置在$HOME/.condarc或者C:\users\[username]\.condarc文件中,可通过文本编辑器直接进行如下修改(直接拷贝如下配置即可)。

    1. channels:
    2. - defaults
    3. show_channel_urls: true
    4. default_channels:
    5. -
    6. -
    7. -
    8. custom_channels:
    9. conda-forge:
    10. msys2:
    11. bioconda:
    12. menpo:
    13. pytorch:
    14. pytorch-lts:

    2. pip安装源

    虽然也可以通过配置文件永久安装,我们更推荐快速命令安装:

    1. """
    2. 1、采用国内源,加速下载模块的速度
    3. 2、常用pip源:
    4. -- 清华: https://pypi.tuna.tsinghua.edu.cn/simple/
    5. -- 中科大: https://pypi.mirrors.ustc.edu.cn/simple/
    6. -- 阿里: https://mirrors.aliyun.com/pypi/simple/
    7. -- 豆瓣: https://pypi.douban.com/simple/
    8. 3、加速安装的命令:
    9. -- >: pip install -i https://pypi.douban.com/simple 模块名
    10. """

    二、寻根溯源(安装包与当前Python版本不匹配)

    1.多版本python安装导致匹配混乱

    电脑安装多个python版本,安装包也已经安装,但不能正确将安装包与python进行匹配。可使用python --version以及conda list等命令查看当前conda环境是否安装了响应本,如未安装,切换其它虚拟环境进行尝试。

    2. 未有当前版本的安装本

    多次尝试使用命令进行安装,最终痘失败,可能使python版本过旧或者过新而未有相应版本python支持,此种情况通常可以使用再次安装支持该包的某一python版本(常使用可选最新稳定版)。

  • 相关阅读:
    Gradle之属性Properties
    论文阅读笔记 | 三维目标检测——PointNet
    C++ Reference: Standard C++ Library reference: C Library: ctime: time
    RabbitMQ学习一 安装
    git学习——第5节 远程仓库
    springboot项目使用拦截器和注解方式验证token
    C++智能指针(三)——unique_ptr初探
    Python爬虫实战:抓取和分析新闻数据与舆情分析
    2024目前三种有效加速国内Github
    论文办公绘图编写工具
  • 原文地址:https://blog.csdn.net/jebeljebel/article/details/133283312