0.前言
conda 是一个开源的包、环境管理器,可以用于在同一个机器上创建不同的虚拟环境,安装不同 python 版本的软件包及其依赖,并能够在不同的虚拟环境之间切换。conda常通过安装anaconda/miniconda来进行使用。一般使用miniconda就够了。
1.miniconda安装
下载miniconda安装包
wget https://repo.anaconda.com/miniconda/miniconda3-latest-linux-x86_64.sh
安装miniconda
bash miniconda3-latest-linux-x86_64.sh ... please answer 'yes' or 'no':' >>> yes ... miniconda3 will now be installed into this location: /root/miniconda3 - press enter to confirm the location - press ctrl-c to abort the installation - or specify a different location below [/root/miniconda3] >>> ... you can undo this by running `conda init --reverse $shell`? [yes|no] [no] >>> yes
配置国内镜像源
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/pkgs/r conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2 conda config --set show_channel_urls yes
到此,安装完成。
2.conda本地基本操作
获取版本号
conda --version 或 conda -v
检查更新当前conda
conda update conda
查看当前存在哪些虚拟环境
conda env list 或 conda info -e 或 conda info --envs
查看/安装/更新/删除包
conda list: conda search package_name conda install package_name conda install package_name=1.5.0 conda update package_name conda remove package_name
3.创建conda虚拟环境
创建名为your_env_name的环境
conda create --name your_env_name
创建制定python版本的环境
conda create --name your_env_name python=3.12
创建包含某些包的环境
conda create --name your_env_name numpy scipy
创建指定python版本下包含某些包的环境
conda create --name your_env_name python=3.12 numpy scipy
4.激活conda虚拟环境
linux
conda activate your_env_name
windows
activate your_env_name
5.退出conda虚拟环境
linux
conda deactivate
windows
deactivate env_name
6.删除conda虚拟环境
conda remove -n your_env_name --all conda remove --name your_env_name --all
7.克隆conda虚拟环境
conda create --name new_env_name --clone old_env_name
到此这篇关于python中conda虚拟环境创建及使用小结的文章就介绍到这了,更多相关python conda虚拟环境创建内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论