Conda 常用命令及Pycharm项目应用

文章目录

一、Conda 常用命令

1.获取帮助

bash 复制代码
conda -h 							# 获取帮助
conda env -h	

2.更新

bash 复制代码
conda --version 					# 查看版本信息
conda update conda          
conda update anaconda      
conda update --all                	# 更新全部包 
conda update xxx   					# 更新xxx文件包

3.环境相关操作

bash 复制代码
conda env list                    	# 显示所有的虚拟环境
conda create --name newname --clone oldname  # 创建一个newname的新环境,里面的包与oldname相同
conda create -n xxxx python=3.9   	# 创建python3.9的xxxx虚拟环境,创建新环境的时候最好指定python具体版本,不要创建空环境
conda activate xxxx               	# 激活虚拟环境,可用于不同环境互相切换
conda list         					# 查看当前环境中已经安装的包
conda deactivate 					# 退出环境

进入、退出虚拟环境来激活指定的虚拟环境

bash 复制代码
conda activate <虚拟环境名称>   # conda 进入虚拟环境来激活指定的虚拟环境。
#当成功激活后,命令行前会显示 (<虚拟环境名称>),表示已经进入了该虚拟环境

 conda deactivate   #退出虚拟环境并返回到默认环境

查询当前环境安装的依赖库

windows

bash 复制代码
(base) C:\Users\EDY>conda list |findstr numpy   #在win环境下,查找是否安装numpy库
numpy                     1.26.4          py311hdab7c0b_0
numpy-base                1.26.4          py311hd01c5d8_0
numpydoc                  1.5.0           py311haa95532_0

Linux环境

bash 复制代码
conda list | grep numpy  #在linux环境下查找是否安装numpy库

4.卸载包

bash 复制代码
conda search package_name			# 可以在安装具体的某款包前查找conda库中是否有对应的版本
conda instal xxx					# 安装xxx文件包
conda uninstall xxx   				# 卸载xxx文件包
conda remove -n xxxx --all   		# 删除xxxx虚拟环境
# 下面的删除就是清理缓存
conda clean -p     					# 删除没有用的包,清理缓存
conda clean -t						# 删除tar安装包
<hr> 

二、Conda数据源管理

bash 复制代码
# 显示目前conda的数据源有哪些
conda config --show channels 
# 添加数据源:例如, 添加清华anaconda镜像:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
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/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
bash 复制代码
# 添加中科大镜像
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 --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/pytorch/
bash 复制代码
# 上海交大镜像源
conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.sjtug.sjtu.edu.cn/anaconda/cloud/conda-forge/
bash 复制代码
# linux 系统 将以上配置文件写在~/.condarc中  vim ~/.condarc
# 安装包时显示具体来源
conda config --set show_channel_urls yes
# 删除指定数据源
conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
# 恢复默认数据源 
conda config --remove-key channels

三、requirements相关

bash 复制代码
pip freeze > requirements.txt 		# 生成一个所需环境包的txt文件
# 使用conda和pip安装相应的包
while read requirement; 
do conda install --yes $requirement || pip install $requirement; done < requirements.txt 

总结

conda常用命令,希望可以帮助大家更好的管理自己的conda环境

conda切换国内源

conda会默认从国外服务器上下载包,这将导致下载速度非常缓慢,因此常切换成国内的清华源、阿里源,也就是官网的镜像网站。

安装conda后在命令行中输入以下指令:(如果没有将conda添加到PATH,需要打开conda prompt)

bash 复制代码
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
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/conda-forge/
conda config --set show_channel_urls yes

安装完后可以查看conda当前源

bash 复制代码
conda config --get channels

配置环境变量

把conda集成到Pycharm开发环境

文件-》设置-》项目》解释器》添加解释器》左侧选择conda环境》选择环境目录

相关推荐
在路上@Amos19 小时前
conda 安装
conda
神秘剑客_CN2 天前
ubuntu26.04音频转srt字幕
ubuntu·conda·whisperx
积跬步,慕至千里8 天前
解决 Conda 环境在 Jupyter Notebook 中不显示的问题(含重复 Kernel 排查)
windows·jupyter·conda
咕噜咕噜啦啦9 天前
RTX5090配置DGL
pytorch·python·conda·pip
马优晨11 天前
Pip 和 Conda 是什么关系?
conda·pip·pip 和 conda 关系·conda和pip的关系·pip和conda是什么
yuanpan11 天前
Python 与 Conda 编程实战指南:从环境配置到项目运行完整入门
开发语言·python·conda
其实防守也摸鱼12 天前
VS code怎么使用 Conda 安装预编译包
开发语言·网络·c++·vscode·安全·web安全·conda
独隅12 天前
Anaconda、Miniconda 与 Conda 全面对比:核心差异、适用场景与选型指南
conda
独隅12 天前
Anaconda 与 Conda 全面对比:核心差异、适用场景与选型指南
conda
Robot_Nav12 天前
Python 虚拟环境完全指南:venv、virtualenv 与 Conda
python·conda·virtualenv