Software Development in Linux-Install miniconda in WSL

Mostafa Farrag
Hydroinformatics
Published in
6 min readJun 14, 2023

This article is a part of an article series about Software development in Linux, I started it by explaining the benefits of working on Linux and explained how to install Windows Subsystem for Linux WSL in Windows,

In This article, I will explain, How to install miniconda in Windows Subsystem for Linux, and How to integrate it with Pycharm IDE.

So let’s start directly

  • First, we need to download the version of miniconda from Anthe aconda website here (Link), you will find different versions and different architectures for each installer. In our case, we want a Linux installer, and we want to install Python version 3.10, so we will choose Miniconda3 Linux-64-bit.
  • Another way of downloading miniconda is by using the wget command in the terminal, followed by the path to the miniconda version that we want. The path consists of two parts, the first is https://repo.anaconda.com/miniconda, and the second is the miniconda version name, which you can get from here (Link)
wget https://repo.anaconda.com/miniconda/<version-name> 
  • so the same version we downloaded above we can get it using the following command
wget https://repo.anaconda.com/miniconda/Miniconda3-py310_23.3.1-0-Linux-x86_64.sh
  • After Downloading miniconda, browse to the directory where the shell script
  • Change the execution privilege of the file using chmod command, (change the name of the downloaded file to your file name)
chmod +x Miniconda3-py310_23.3.1-0-Linux-x86_64.sh
  • Then execute the shell script, it will download the miniconda package and install it
./Miniconda3-py310_23.3.1-0-Linux-x86_64.sh
  • Then confirm the installation directory or change it. Thedefault directory will be in a folder named “miniconda3” in the home directory
  • Now if you browse to the Home directory, you will find the installation folder of miniconda, however, if you tried the conda command in the terminal, you will get an error.
  • The solution is to add the bin folder which exists in the miniconda installation directory to the environment variable.
  • To add the bin path to the environment variable we have to add the export command to the .bashrc file
export PATH=$PATH:/<change to your path>/miniconda3/bin
  • so the bottom of the .bashrc file will look like this
  • Now source the .bashrc file to apply the changes.
source ~/.bashrc
  • Now if you try the conda command again, it has to work
  • Conda is now installed and you can create your environments, I have explained in detail, how to create environments in different ways in this article (Link), you can check it and follow the steps there to create your environment.
  • Now miniconda is installed, and we can create environments exactly the same way as in Windows.
  • I have explained in a previous article how to work with conda in detail you check it out here.
  • we will create a very simple environment that has only python 3.10
conda create -n pyramids python=3.10
  • Now we have two environments, the base environment, and the pyramids environment we have just created.

Now we have finished installing conda and created an environment to work with. For an in-detail tutorial on how to work with conda and create an environment from an environment.yml/requirement.txt file, check out my conda article

Pycharm Integration

  • Now we can integrate the environment we have just created into Pycharm IDE, and to do that, open your Pycharm IDE, and from the file pull-down menu, press on “Setting”.
  • the setting window will pop up. Fromthe left panel, select Project, then Python Interpreter.
  • After selecting the Python Interpreter, the right panel will look like the picture below, then select Add Interpreter, then select On WSL
  • when selecting “On WSL” Pycharm will check WSL and search for environments.
  • press next, in the new window, select “Conda Environment”, and from the right part of the window, choose “Use existing environment” and select the environment that we have created, then press “Create”.
  • Now if you open the Python console in Pycharm, you will find that Pycharm initialized the console using the conda environment that we have created on WSL.
  • Now to fully operate the environment from the terminal, you can either still use the WSL terminal that we have been using since the beginning, or we can open WSL in the terminal integrated into Pycharm, and activate our conda environment.
  • Open the terminal and check the list of installed WSL, then open the WSL you want
wsl -l -v
wsl
  • Now WSL is activated in our Pycharm terminal, however, if you try the conda command, the terminal will not recognize it.
  • I have explained in a separate article the process of installing WSL and some of the common terminal commands you need to know to navigate your way in the bash terminal; you can check it out here.
  • As I have explained in the above article about WSL, the first step we have to do when we open WSL, is to trigger the .bashrc file to configure our terminal.
source ~/.bashrc
  • Now we can use the conda command, as the installation directory of conda is added to the PATH environment variable inside the .bashrc script.
  • The last this we have to do is to activate our conda environment.

So In this article, I have explained how to install conda in WSL, and how to integrate the Python environment into Pycharm in Windows. In the next article, I will explain dpkg and apt, which are tools you have to know to install packages in Linux.

References

[1] Getting Started with Windows Sub System for Linux (WSL)-Installation & Command Line, https://mafarrag.medium.com/getting-started-with-windows-sub-system-for-linux-wsl-installation-68d8bf15175c

[2] Getting Started with Conda environment [Part-1], https://medium.com/hydroinformatics/getting-started-with-conda-environment-332182d1e937

[3] How to make your Python environment reproducible (common practices) — Conda environment series[Part-3], https://medium.com/hydroinformatics/how-to-make-your-python-environment-reproducible-common-practices-conda-environment-de28195b74de

[2] Miniconda installer, https://docs.conda.io/en/latest/miniconda.html#installing

[2] Miniconda hashes, https://docs.conda.io/en/latest/miniconda_hashes.html

--

--