Skip to content

Conda

Conda is a tool for package dependency and virtual environment management. The system image has miniconda installed.

virtual environment

warning

The disk space in the instance has a capacity limit. Because the virtual environment requires a large capacity to install software packages, it is recommended to put the virtual space location in the shared space /hy-nas (with shared storage models) or /hy-tmp local disk Down.

# View all virtual environments
conda env list

# Create a virtual environment for Python 3.9 at /hy-tmp/myenv
conda create -p /hy-tmp/myenv python=3.9

# Activate the virtual environment
conda activate /hy-tmp/myenv

# Exit the virtual environment
conda deactivate

## delete virtual environment
conda remove -p /hy-tmp/myenv --all

tip

The login terminal cancels the automatic entry into the base environment by default. If you want to enter the base environment directly after login, you need to execute conda config --set auto_activate_base true.

package management

tip

When installing frameworks such as PyTorch, please strictly refer to the installation instructions on the official website. The same version may support multiple CUDA versions. RTX 3000 series graphics cards only support CUDA 11 and above, you need to pay attention to specifying the version of the cudatoolkit package.

The mirror source has been configured in /root/.condarc. Note that when installing PyTorch, do not specify -c pytorch at the end, if specified, it will still be downloaded from the official source.

# Activate the virtual environment
conda activate /hy-tmp/myenv

# search for packages
conda search spacy

# install package
conda install spacy=2.3.5

## View installed packages
conda list

JupyterLab

JupyterLab uses the system Python in the instance image by default. If you need to use a virtual environment with Notebook, you need to install ipykernel in the virtual environment.

# Activate the created virtual environment
conda activate myenv

# Install ipykernel in the virtual environment
conda install ipykernel

# install kernel, --name custom name
ipython kernel install --user --name myenv

# Can be deleted when the kernel is not needed
jupyter kernelspec remove myenv

After the installation is complete, in the JupyterLab menu, open File - New Startup Page. You can see that there are more virtual environments that have just been created, and the Notebook that you click to open is in the virtual environment.