Essential Anaconda Commands for Environment Management and Jupyter Integration
Managing Anaconda Environments
Listing Available Environments
To view all your Conda environments, use:
conda env list
Configuring Conda Package Sources
Optimize your package downloads by adding mirrors. For example, to add Tsinghua University's mirror:
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/main/
conda config --set show_channel_urls yes
Verifying Configuration
Check your current Conda configuraton with:
conda info
Testing Package Installation
Verify that your source changes are working by attempting to install a package:
conda install
Creating New Environments
Create a new environment with specific Python version and packages:
conda create -n myenv python=3.9 numpy pandas
Switching Between Environments
Activate an environment to use it:
activate myenv
Deactivating Current Environment
Exit the current environment:
deactivate
Cloning Environments
Duplicate an existing environment with all its packages:
conda create --name new_env --clone existing_env
Removing Environments
Delete an environment and all its packages:
conda remove -n env_name --all
Configuring Pip Sources
Setting Up Pip Configuration
Create a pip configuration file for faster downloads. First, create a directory in your user profile:
mkdir %USERPROFILE%\pip
Then create a pip.ini file in that directory with the following content:
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn
disable-pip-version-check = true
timeout = 6000
Updating Pip
Ensure you have the latest pip version:
python -m pip install --upgrade pip
Integrating Environments with Jupyter
Preparing the Environment
First, activate the environment you want to add to Jupyter:
activate your_env_name
Installing IPython Kernel
Install the necesssary package to make your environment available to Jupyter:
pip install --user ipykernel
Adding Environment to Jupyter
Register your environment as a Jupyter kernel:
python -m ipykernel install --user --name=your_env_name
If you see a message like "Installed kernelspec your_env_name in /home/user/.local/share/jupyter/kernels/your_env_name", the environment was successfully added.
Removing Environments from Jupyter
List available kernels:
jupyter kernelspec list
Remove a specific kernel:
jupyter kernelspec uninstall kernel_name