ChiChieh HuangFOUNDER · AI ENGINEER

Installing conda on WSL2

Date2023.12.28
Length525 words
Reading~3 min
Figures2 figures
ChiChieh HuangFounder · AI engineer

Translated from the Chinese original · Read the original

LocatorData Lowlands
2 wks
Overview

Introduction

In today’s varied development environments, the Windows Subsystem for Linux (WSL) is a great way to run a Linux environment on Windows. Conda is a popular package and environment management system that supports multiple languages and is especially well suited to data science and machine learning. Installing Conda on WSL lets developers easily manage packages and dependencies in a Linux environment on a Windows machine.

Preparation

Before installing Conda, you need to enable and install WSL on Windows 10 or later. That usually means choosing a Linux distribution (like Ubuntu) from the Microsoft Store and completing the installation. Once it’s installed, you can use the Linux version of Python and conda directly in WSL.

Installation steps

  1. Open WSL: start your Linux distribution.
  2. Go to the Anaconda repo and find the release that suits you

Choose the version you want. I have a 64-bit computer, so I chose the latest version ending in x86_64.sh. If I had a 32-bit computer, I’d choose the x86.sh version. If you accidentally try to install the wrong version, you’ll get a warning in the terminal. I chose Anaconda3-2023.09-0-Linux-x86_64.sh.

  1. You can click to download it directly, or download it with wget in the terminal.
wget https://repo.continuum.io/archive/Anaconda3-2023.09-0-Linux-x86_64.sh
  1. Then run the install script in the terminal with this command:
bash Anaconda3-2023.09-0-Linux-x86_64.sh
  1. Reload your environment:
source ~/.bashrc

Configuring environments

Once installation is done, you can start configuring Conda environments. Create a new environment with conda create, and activate it with conda activate. You can also install the packages you need with conda install. Here are some commonly used commands.

1. create

  • What it does: creates a new Conda environment. In this environment you can install specific versions of packages without affecting other environments.
  • Example: conda create --name myenv python=3.8. This creates a new environment called myenv and installs Python 3.8 in it.

2. activate

  • What it does: activates a specific Conda environment, making it the one currently in use.
  • Example: conda activate myenv. This activates the environment called myenv.

3. deactivate

  • What it does: deactivates the currently active Conda environment and returns to the base environment or the previous one.
  • Example: conda deactivate. This exits the currently active environment.

4. install

  • What it does: installs packages into the currently active Conda environment.
  • Example: conda install numpy. If you’re in the myenv environment, this installs NumPy into it.
  • To install the packages in a requirements.txt like pip does, use:
conda install - yes - file requirements.txt

5. remove

  • What it does: removes a Conda environment.
  • Example: conda remove -n myenv --all. This removes the myenv environment and every package installed in it.

Common problems and troubleshooting

If you use zsh, typing conda after installation may give an error:

zsh: command not found: conda

In that case, edit ~/.zshrc and add the path to anaconda or miniconda:

vim ~/.zshrc

# added by conda nstaller
export PATH="/Users/username/miniconda3/bin:$PATH"

After reloading, you can use conda in zsh, but features like create still won’t work. So next we set it up with conda init zsh; see Stack Overflow. With that, conda works in zsh.

source ~/.zshrc
conda init zsh 

Support

If this article helped you, or you’d like to encourage me to keep writing, you can clap for it or buy me a coffee through the link below. Thank you for your support!

#wsl-2#conda#installation#performance

End of the trail

525 words, and you made it to the end.

Newsletter

Get the next essay by email.

One email when a new essay goes up, nothing else. Unsubscribe in one click.

ChiChieh Huang
Surveyor

ChiChieh Huang

I build generative AI products and write about them, first in Chinese. Lately I’ve been researching agent memory and testing the ideas in Cairn.