Python 集成 Conda

激活Conda环境

bash 复制代码
# 1.初始化一次
#让 PowerShell 认识 conda 命令、支持 conda 激活环境
#⚠️执行完必须关闭 PyCharm 终端,重新打开终端才生效!
conda init powershell 

# 已有源可以跳过下面两行
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 create 创建虚拟环境
## -n 命名
## -y 后面询问【是否确认创建】自动选 yes,不用手动打字确认
## 指定这个环境里的 Python 版本固定为 3.11.13
conda create -n rag_project python==3.11.13 -y  

## 进入刚刚建好的 rag_project 虚拟环境
conda activate rag_project

## pip install 安装 python 第三方库
## -r requirements.txt 读取当前文件夹里的 requirements.txt 文件
## 程序自动一次性全部安装,不用一个个手动 pip install
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

⚠️两个最容易踩的坑
conda init powershell 运行后一定要重启终端,否则 activate 依然报错
必须看到 (rag_project) 前缀,再执行 pip,不然包装错地方

# 列出本机所有conda虚拟环境
conda env list

如果安装失败
conda deactivate
conda remove -n rag_project --all -y

Pycharm导入conda

命令全部跑完之后,必须在 PyCharm 选中 rag_project这个虚拟环境的 Python 解释器,不然 PyCharm 还是用旧环境,代码运行提示找不到包!

一、操作步骤(Windows PyCharm)

  1. 打开顶部菜单:FileSettingsProject:你的项目名Python Interpreter
  2. 右上角点击齿轮图标 ⚙️ → Add Interpreter
  3. 左侧选择 Conda Environment✅ 选择 Existing environment(已有环境)不要选 New environment!
  4. 找到解释器路径:conda 环境 rag_project 的 python 路径大致位置:

Anaconda 安装目录 /envs/rag_project/python.exe

示例参考:

C:\Users\你的用户名\anaconda3\envs\rag_project\python.exe

  1. 选中 python.exe → 点击 OK 保存

PyCharm 2023 配置 conda 已有环境 rag_project(Windows 完整步骤)

相关推荐
默_笙1 天前
🍙 给每个请求过安检:FastAPI 是怎么把校验写进类型注解的
python
小羊没烦恼!1 天前
初探性能优化——2个月到4小时的性能提升
java·开发语言·windows·算法·c#
qq_426003961 天前
启动playwright录制codegen生成自动化测试脚本
python·自动化
虎头金猫1 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
长沙三为智能科技1 天前
家政小程序开发从0到上线:五阶段交付流程与验收清单
python
伞伞悦读1 天前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
只睡四小时1 天前
Canvas 弹道联机实战:700 行 + 固定时间步长
python·websocket·html5·游戏开发·canvas
C语言小火车1 天前
C/C++ 为什么需要编译器?
开发语言·c++
奇思妙想聪明勤奋的小羊1 天前
DeepAgents第5章:子Agent 与上下文隔离—让 Agent学会委派
人工智能·python·学习·语言模型
lpfasd1231 天前
2026年第38周GitHub趋势周报
python·科技·github