Environment management is one of the key features of AI Lab. By associating an environment in a Notebook , you can quickly switch between different environments, making it easier for them to develop and debug.
In the Notebook, both conda and mamba are provided as environment management tools. You can choose the appropriate tool based on their needs.
In AI Lab, you can use the conda environment management tool. You can view the list of current environments in the Notebook by using the command !conda env list.
(base)jovyan@chuanjia-jupyter-0:~/yolov8$condaenvlist
# conda environments:#dkj-python312-pure/opt/baize-runtime-env/dkj-python312-pure/conda/envs/dkj-python312-pure
python-3.10/opt/baize-runtime-env/python-3.10/conda/envs/python-3.10
torch-smaple/opt/baize-runtime-env/torch-smaple/conda/envs/torch-smaple
base*/opt/conda# Currently activated environmentbaize-base/opt/conda/envs/baize-base
This command lists all conda environments and adds an asterisk (*) before the currently activated environment.
In JupyterLab, the environments associated with the Notebook are automatically bounded to the Kernel list, allowing you to quickly switch environments through the Kernel.
With this method, you can simultaneously write and debug algorithms in a single Notebook.
If you prefer managing and switching environments in the Terminal, you can follow these steps:
Upon first starting and using the Notebook, you need to execute conda init, and then run conda activate <env_name> to switch to the proper environment.
(base)jovyan@chuanjia-jupyter-0:~/yolov8$condainitbash# Initialize bash environment, only needed for the first usenochange/opt/conda/condabin/conda
change/opt/conda/bin/conda
change/opt/conda/bin/conda-env
change/opt/conda/bin/activate
change/opt/conda/bin/deactivate
change/opt/conda/etc/profile.d/conda.sh
change/opt/conda/etc/fish/conf.d/conda.fish
change/opt/conda/shell/condabin/Conda.psm1
change/opt/conda/shell/condabin/conda-hook.ps1
change/opt/conda/lib/python3.11/site-packages/xontrib/conda.xsh
change/opt/conda/etc/profile.d/conda.csh
change/home/jovyan/.bashrc
actiontaken.
Addedmambato/home/jovyan/.bashrc
==>Forchangestotakeeffect,closeandre-openyourcurrentshell.<==(base)jovyan@chuanjia-jupyter-0:~/yolov8$source~/.bashrc# Reload bash environment(base)jovyan@chuanjia-jupyter-0:~/yolov8$condaactivatepython-3.10# Switch to python-3.10 environment(python-3.10)jovyan@chuanjia-jupyter-0:~/yolov8$condaenvlist
mambaversion:1.5.1
# conda environments:#dkj-python312-pure/opt/baize-runtime-env/dkj-python312-pure/conda/envs/dkj-python312-pure
python-3.10*/opt/baize-runtime-env/python-3.10/conda/envs/python-3.10# Currently activated environmenttorch-smaple/opt/baize-runtime-env/torch-smaple/conda/envs/torch-smaple
base/opt/conda
baize-base/opt/conda/envs/baize-base
If you prefer to use mamba, you will need to use mamba init and mamba activate <env_name>.
One important feature of different environment management is the ability to use different packages by quickly switching environments within a Notebook.
You can use the command below to view all packages in the current environment using conda.
(python-3.10)jovyan@chuanjia-jupyter-0:~/yolov8$condalist
# packages in environment at /opt/baize-runtime-env/python-3.10/conda/envs/python-3.10:## Name Version Build Channel_libgcc_mutex0.1maindefaults
_openmp_mutex5.11_gnudefaults
...# Output truncatedidna3.7py310h06a4308_0defaults
ipykernel6.28.0py310h06a4308_0defaults
ipython8.20.0py310h06a4308_0defaults
ipython_genutils0.2.0pyhd3eb1b0_1defaults
jedi0.18.1py310h06a4308_1defaults
jinja23.1.4py310h06a4308_0defaults
jsonschema4.19.2py310h06a4308_0defaults
jsonschema-specifications2023.7.1py310h06a4308_0defaults
jupyter_client7.4.9py310h06a4308_0defaults
jupyter_core5.5.0py310h06a4308_0defaults
jupyter_events0.8.0py310h06a4308_0defaults
jupyter_server2.10.0py310h06a4308_0defaults
jupyter_server_terminals0.4.4py310h06a4308_1defaults
jupyterlab_pygments0.2.2py310h06a4308_0defaults
...# Output truncatedxz5.4.6h5eee18b_1defaults
yaml0.2.5h7b6447c_0defaults
zeromq4.3.5h6a678d5_0defaults
zlib1.2.13h5eee18b_1defaults