Server Setup, Part II: Python Environments with Conda

Jun 17, 2025 · 3 min read

This series records how I set up a remote GPU server for deep learning work. Part I covers SSH and Git; this part covers Python environments.

Conda manages isolated environments, each with its own Python version and packages. On a shared server this keeps projects from interfering with each other and avoids depending on the system Python.

Choosing a distribution

There are three common installers:

  • Anaconda includes several hundred preinstalled packages and needs several gigabytes.
  • Miniconda includes only conda and Python. Packages are installed as needed.
  • Miniforge is similar to Miniconda but uses the community conda-forge channel by default.

On a server, Miniconda or Miniforge is usually the better choice. The packages in Anaconda’s default channels are covered by Anaconda’s terms of service, which require a paid license for some organizations; if this applies to your institution, Miniforge avoids the issue. The commands below are the same for all three.

Installation

Download the installer for Linux and run it. For Anaconda (check the archive for the current version):

curl -O https://repo.anaconda.com/archive/Anaconda3-2024.10-1-Linux-x86_64.sh
bash Anaconda3-2024.10-1-Linux-x86_64.sh

The installer asks you to accept the license and choose an install location; the default under your home directory is fine. When it asks whether to run conda init, answer yes. This adds a block to ~/.bashrc so that conda is available in new shells.

Open a new shell afterwards. The prompt should begin with (base), which means the default environment is active. If you prefer not to activate it automatically, run conda config --set auto_activate_base false.

Environments

Create one environment per project rather than installing into base.

TaskCommand
Create an environmentconda create -n my_project python=3.11
Activate itconda activate my_project
Deactivateconda deactivate
List environmentsconda env list
Remove an environmentconda remove -n my_project --all
Export to a fileconda env export > environment.yml
Recreate from a fileconda env create -f environment.yml

Packages

Packages are installed into the active environment.

TaskCommand
Install packagesconda install numpy pandas matplotlib
List installed packagesconda list
Update a packageconda update pandas
Update everythingconda update --all
Remove a packageconda remove matplotlib

pip also works inside a conda environment and installs into it. When mixing the two, install conda packages first and pip packages afterwards, since conda does not track what pip installed. PyTorch is a common case: recent releases are distributed through pip rather than conda, so use the command generated on pytorch.org for your CUDA version.

Mirrors

Downloads from the default servers can be slow from some regions, including mainland China. pip and conda are configured separately.

For pip, set a mirror index, for example the Tsinghua (TUNA) mirror:

pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple

For conda, edit ~/.condarc. The configuration recommended by TUNA is:

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

Run conda clean -i afterwards to clear the cached index. The TUNA help page lists the current configuration.