python使用pycharm和conda 设置默认使用清华镜像

发布于:2025-05-25 ⋅ 阅读:(26) ⋅ 点赞:(0)

将步骤分为Conda配置和PyCharm配置两部分。Conda部分包括添加镜像源、调整优先级、更新环境。PyCharm部分需要根据版本说明如何添加镜像源到项目解释器设置中。同时,需要验证配置是否成功,并提醒常见问题,比如路径错误或缓存问题。需要确保引用正确的网页编号,如等,避免重复引用同一个来源。

以下是配置 PyCharm 和 Conda 使用清华镜像源的完整指南:

一、Conda 镜像源配置

  1. ​​基础镜像源设置​​
    执行以下命令添加清华镜像源并设置优先级:

清除旧配置(可选)

conda config --remove-key channels

添加主镜像源

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 --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/

设置通道优先级

conda config --set channel_priority strict
2. ​​验证配置​​
查看配置文件 ~/.condarc,确认包含以下内容:

channels:

  • https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  • https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
  • https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  • https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  • https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
    show_channel_urls: true
  1. ​​环境更新​​
    执行以下命令同步最新包列表:

conda clean -i # 清除旧缓存
conda update --all
二、PyCharm 配置

  1. ​​全局镜像源设置​​
    针对不同版本:

​​2018及更早版本​​:通过 File > Settings > Project Interpreter > Manage Repositories 删除默认源,添加 https://pypi.tuna.tsinghua.edu.cn/simple
​​2021-2022版本​​:在项目设置中点击 Python Interpreter 右侧齿轮图标,选择 Show All > 点击 Manage Repositories 添加清华源
​​2023新UI​​:通过 File > Settings > Tools > Server Certificates 勾选 “Auto-accept non-trusted certificates”
2. ​​Conda环境绑定​​
在创建新项目时:

选择 Conda Environment 类型
指定路径为 Anaconda 安装目录下的 envs/[环境名]/python.exe
勾选 Make available to all projects 实现全局配置
三、验证与问题排查
​​验证命令​​:
conda config --show channels # 应显示清华源列表
conda list | grep numpy # 测试包下载来源
​​常见问题​​:
​​HTTP连接错误​​:执行 conda clean -i 清除索引缓存
​​环境变量失效​​:检查系统 PATH 是否包含 Anaconda/Scripts 路径
​​混合源冲突​​:建议完全移除 defaults 频道,仅保留清华源
通过以上配置,PyCharm 和 Conda 将优先从清华镜像站获取资源,速度可提升 5-10 倍。若需恢复默认源,执行 conda config --remove-key channels。


网站公告

今日签到

点亮在社区的每一天
去签到