安装
使用Conda
进行Python
环境的管理,便于python环境的切换和统一,国内conda
安装官方地址由于网路问题,基本很难成功,如下使用清华的镜像实现conda的安装:
$ cd /opt
$ wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh
$sh Miniconda3-latest-Linux-x86_64.sh
环境查看
后面一路yes
就可以了。通过conda info
查看安装结果:
$ (base) root ➜ /com.docker.devenvironments.code (master ✗) $ conda info
active environment : base
active env location : /root/miniconda3
shell level : 1
user config file : /root/.condarc
populated config files :
conda version : 24.5.0
conda-build version : not installed
python version : 3.12.4.final.0
solver : libmamba (default)
virtual packages : __archspec=1=skylake
__conda=24.5.0=0
__glibc=2.28=0
__linux=5.15.133.1=0
__unix=0=0
base environment : /root/miniconda3 (writable)
conda av data dir : /root/miniconda3/etc/conda
conda av metadata url : None
channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/linux-64
https://repo.anaconda.com/pkgs/r/noarch
package cache : /root/miniconda3/pkgs
/root/.conda/pkgs
envs directories : /root/miniconda3/envs
/root/.conda/envs
platform : linux-64
user-agent : conda/24.5.0 requests/2.32.2 CPython/3.12.4 Linux/5.15.133.1-microsoft-standard-WSL2 debian/10.10 glibc/2.28 solver/libmamba conda-libmamba-solver/24.1.0 libmambapy/1.5.8 aau/0.4.4 c/. s/. e/.
UID:GID : 0:0
netrc file : None
offline mode : False
如上看到conda主动激活了一个base的python环境
基础操作
1、创建一个虚拟环境
我们可以通过conda创建一个指定python版本的虚拟环境,如下
$ conda create --name venv python=3.8
2、查看所有虚拟环境
$ conda env list
3、切换环境
$ conda activate test
4、删除虚拟环境
$ conda deactivate test # 退出环境
$ conda env remove --name test # 删除环境