This article was written with the assistance of GitHub Copilot
Anaconda or Miniconda?
Conda is a package manager that runs on Linux, Windows and macOS, and it ships
Python with it — which is why a single conda create -n new_pyenv python=3.12
is enough to get a clean virtual environment.
There are two common distributions:
- Anaconda is large. The installer already bundles a lot of software and libraries, so you get everything in one shot.
- Miniconda is small. Whatever library an environment needs gets downloaded on demand.
If your network is unreliable, Anaconda saves you the repeated downloads — although in mainland China the network problem is usually better solved by switching to a mirror. On an overseas connection (Hong Kong, in my case) I’d just take Miniconda: it installs fast, and when you inevitably get the paths wrong as a beginner, uninstalling and reinstalling is painless. That is exactly how I figured it out.
The official site documents installation clearly for every platform and for both distributions, so I won’t repeat it. Two of the install-time options are worth a word of warning though.
Two options I would not enable
❌ Add conda to the system PATH
Don’t. Putting conda on the global PATH makes it shadow other Python
installations and conflict with environments you set up elsewhere. Let the
conda shell hook handle activation instead.
⚠️ Auto-activate the base environment (conda init)
conda init makes every new shell run conda activate automatically. I don’t
think it’s worth it, especially on Windows: if PowerShell is initialised this
way, every single PowerShell window takes ages to load. I used to blame my
laptop for that — turns out I had been misjudging Windows all along.
Running it for cmd instead has basically no impact:
conda init cmd.exe
If you already enabled it for PowerShell and want it back, undo it with:
conda init --reverse powershell
Create a new environment
To create a new conda environment, use the following command:
conda create --name myenv
Replace myenv with the name you want for your environment. You can also specify the Python version:
conda create --name myenv python=3.8
Alternatively, you can create an environment at a specific path using the -p option:
conda create -p /path/to/myenv
Replace /path/to/myenv with your desired path. You can also specify the Python version:
conda create -p /path/to/myenv python=3.8
Set environment variables for a specific environment
To set environment variables for a specific conda environment, use the conda env config vars set command. For example:
conda env config vars set MY_VAR=value
Replace MY_VAR and value with your desired variable name and value.
Activate the environment to apply the changes:
conda activate myenv
To view the environment variables set for the active environment, use:
conda env config vars list
To unset an environment variable, use:
conda env config vars unset MY_VAR
Replace MY_VAR with the name of the variable you want to unset.
For more details, refer to the official conda documentation.
Example: Setting PYTHONPATH
To set the PYTHONPATH environment variable for a specific conda environment, use the following command:
conda env config vars set PYTHONPATH=/path/to/your/modules
Replace /path/to/your/modules with the path you want to add to PYTHONPATH.
Activate the environment to apply the changes:
conda activate myenv
To verify that PYTHONPATH has been set, you can list the environment variables:
conda env config vars list
Delete an environment
To delete a conda environment, use the conda remove command with the --name option. For example:
conda remove --name myenv --all
Replace myenv with the name of the environment you want to delete. The --all flag ensures that all packages in the environment are removed.
Alternatively, if you created the environment at a specific path, use the -p option:
conda remove -p /path/to/myenv --all
Replace /path/to/myenv with the path to the environment you want to delete.
For more details, refer to the official conda documentation.