Last updated: Apr 11, 2024
Reading time·3 min
If you need to temporarily change the environment, use the
conda activate ENVIRONMENT_NAME
command.
conda activate <ENVIRONMENT_NAME>
If you need to list your environments, use the conda env list
command.
conda env list
If you need to create a virtual environment, use the following command.
conda create --name my-env
If you are in a conda
environment that uses Python version 3.9.2 and want to
update it to the latest version in the 3.9
branch, then use the following
command.
conda update python
You can also upgrade the Python in a conda
environment to a different version,
e.g. from 3.9
to 3.10
, however, this is not recommended.
It is usually safer to create a new environment.
If you want to create a new environment using a specific Python version, use the following command.
conda create -n <YOUR_ENV_NAME> python=3.10 anaconda
Replace the <YOUR_ENV_NAME>
placeholder with the actual name of the
environment.
The command installs version 3.10
of Python.
If you want to upgrade the Python version of an existing conda
environment,
use the following command.
conda install python=3.10
If you want to permanently change your default Anaconda environment, click on the subheading that relates to your operating system:
If you need to permanently change your default conda environment, you have to
add a command to your startup script (e.g. ~/.bashrc
, ~/.bash_profile
or
~/.zshrc
).
You can use the gedit
command to edit your profile file.
sudo gedit ~/.bashrc sudo gedit ~/.bash_profile sudo gedit ~/.zshrc
Or the nano
command if you prefer to add the line in your terminal.
sudo nano ~/.bashrc sudo nano ~/.bash_profile sudo nano ~/.zshrc
Once you open your profile file, add the activation command at the end of the file.
conda activate <ENVIRONMENT_NAME>
In my case, the command looks as follows:
conda activate my-env
Save the file and source your profile file from your terminal.
source ~/.bashrc source ~/.bash_profile source ~/.zshrc
If you open a new terminal window, you will see that it defaults to the
specified conda
environment.
You can also use the conda env list
to print the active environment.
conda env list
The active environment has an asterisk *
next to its name.
To permanently change your default Anaconda environment on Windows:
C:\Users\YOUR_USER\AppData\Roaming
directory.my_conda_env.cmd
in the AppData
directory.The file should contain your conda
activation command.
conda activate <ENVIRONMENT_NAME>
Now, you have to configure the file to run automatically when CMD (Command Prompt) is started.
Search for Registry and start the Registry Editor application.
HKEY_CURRENT_USER\Software\Microsoft\Command Processor
.You might have to create the Command Processor
key under Microsoft
if it
doesn't already exist.
You simply have to right-click on Microsoft
and select New > Key.
Set the Value name: to AutoRun
.
Set the Value data: to %AppData%\my_conda_env.cmd
.
The next time you open CMD (Command Prompt), the
C:\Users\YOUR_USER\AppData\Roaming\my_conda_env.cmd
file will run.
The file will use the conda activate
command to activate your preferred conda
environment automatically.
You can learn more about the related topics by checking out the following tutorials: