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

将步骤分为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

  1. ​​验证配置​​

查看配置文件 ~/.condarc,确认包含以下内容:

channels:

  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"

  1. ​​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。

相关推荐
databook9 小时前
Manim实现脉冲闪烁特效
后端·python·动效
程序设计实验室9 小时前
2025年了,在 Django 之外,Python Web 框架还能怎么选?
python
倔强青铜三11 小时前
苦练Python第46天:文件写入与上下文管理器
人工智能·python·面试
用户25191624271114 小时前
Python之语言特点
python
刘立军14 小时前
使用pyHugeGraph查询HugeGraph图数据
python·graphql
数据智能老司机18 小时前
精通 Python 设计模式——创建型设计模式
python·设计模式·架构
数据智能老司机19 小时前
精通 Python 设计模式——SOLID 原则
python·设计模式·架构
c8i20 小时前
django中的FBV 和 CBV
python·django
c8i20 小时前
python中的闭包和装饰器
python
这里有鱼汤1 天前
小白必看:QMT里的miniQMT入门教程
后端·python