python

关注公众号 jb51net

关闭
首页 > 脚本专栏 > python > Python conda虚拟环境创建

Python中conda虚拟环境创建及使用小结

作者:鸟哥大大

本文主要介绍了Python中conda虚拟环境创建及使用小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

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虚拟环境创建内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家! 

您可能感兴趣的文章:
阅读全文