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环境》选择环境目录

相关推荐
qq_白羊座18 小时前
‌Miniconda 和 Conda 的关系
conda
萧行之3 天前
CONDA设置、查看、管理源
conda
DeepHacking4 天前
Ubuntu 上安装 ComfyUI(NVIDIA GPU / Conda / CUDA 12.1)
linux·ubuntu·conda
不吃香菜的小趴菜5 天前
conda配置国内镜像源
conda
hui-梦苑6 天前
[Conda]环境激活钩子作用与应用
conda
做cv的小昊6 天前
【conda】打包已有conda环境并在其他服务器上搭建
运维·服务器·python·conda·运维开发·pip·开发
csdn_aspnet7 天前
用Anaconda驯服AI开发流,从数据预处理到模型部署,全链路环境标准化实战
人工智能·docker·ai·conda·anaconda
时光之源8 天前
程序猿常用命令行(Linux、Windows、Powershell、CMD、conda、pip、apt)
linux·conda·pip
YuanDaima204810 天前
解决Conda环境下RTX 50系列显卡PyTorch+Transformers+PEFT微调报错
人工智能·pytorch·笔记·python·深度学习·机器学习·conda
ZzzGo!10 天前
【已解决】conda环境报错:Error while loading conda entry point: conda-libmamba-solver
conda