Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Guide to installing Python with Conda

Installing Python 3 via Conda

This tutorial describes how to install Python 3 into your home directory using the Conda package manager. We'll use the Miniconda variant, which is just Anaconda with fewer packages installed by default.

  1. Download: wget https://repo.anaconda.com/miniconda/Miniconda3-py37_4.8.3-Linux-x86_64.sh
  2. Make executable: chmod +x Miniconda3-py37_4.8.3-Linux-x86_64.sh
  3. Run installer: ./Miniconda3-py37_4.8.3-Linux-x86_64.sh When prompted, say yes when asked if you want to initialize Miniconda.
  4. Close and re-open your shell in order for the installation to take effect. (e.g., close your terminal or SSH connection and then re-open)
  5. Update your conda environment to the latest: conda update -n base -c defaults conda

Usage

You should now have a functioning base Conda environment. It's best to leave this default Conda environment untouched and to create new Conda environments for each project you use.

  • Create a new environment: conda create --name MyNewEnv python=3.7
  • Activate an existing environment: conda activate MyNewEnv
  • Deactivate the current enrivonment: conda deactivate

The standard workflow is to create a separate environment for each project. When switching projects, you then run conda activate <name> to activate the appropriate environment. This replaces the common practice of using a separate Python virtual environment for each project.

Packages can be installed into the Conda environment using both pip and conda. The latter can install non-Python programs in addition to Python packages. The standard practice is to install any needed conda packages first, followed by any pip packages. For example, you can install PyTorch and Java 11:

  • conda install -c conda-forge 'openjdk>=11,<12'
  • conda install -c pytorch pytorch torchvision cudatoolkit=10.1

Followed by Capreolus via pip:

  • pip install capreolus

Additional resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.