How to install and run conda on Google Colab
Tags: conda, googlecolab, python, opensource
Published: 2024-03-02 22:51:12

##  **# Are you sure conda is not already installed in your google colab?**

![conda version](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pocv2gx2snfi1cfq2yc3.png)

If yes! then you will see this output.

![conda exist](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eqn0kj8axmfc746o0uf7.png)

If no, then this output.

![no conda](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rlq17pzy9srgye5djcl3.png)


## **# Which Python and its version**

![command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5sq39fpyx207upuiyrjq.png)

![python version](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ask1rz73nb10zf9zi9d.png)

This means that, in order to use all of the preinstalled Google Colab packages, you will need to install a version of Miniconda that is compatible with Python 3.10 by default. Now it’s miniconda version 4.12.


## **# Check if the PYTHONPATH variable has been set**

![PYTHONPATH](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ydb51kc9znlkkesdl6dx.png)

![path](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0zqa1qf3pd1vchcfp2wm.png)
This directory doesn’t seem to exist within the Google Colab filesystem. So it is a good idea to unset the PYTHONPATH variable before installing Miniconda as it can cause problems if there are packages installed.

![path command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z252o8dyxfm9bf9rvvuw.png)

![pathss](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bd7mntrcfjtvskhdqicq.png)

## **# Installing Miniconda**

![conda script](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sun249uyw2c3m3obfjhz.png)
Adjust the miniconda to the latest version by checking your python version as I showed above.

Just in case you’re wondering what did the above code just did?

Lines 1–3 — are just comments that serve as a note to self for telling us what this block of code is doing.
Line 4 — The wget command is run in the BASH terminal to download the installation script file Miniconda3-py310_24.1.2-0-Linux-x86_64.sh directly from the Anaconda website.
Line 5 — The chmod +x command is run in the BASH terminal to add executable permission (allow the file to be run).

## **# Which Conda and its version**

![conda chk](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/quefgnzq1w3bcuagf2p4.png)

![version](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ilhbcf0f5qdrbuuydjeo.png)

## **# Appending to the sys.path**
You can see the current list of directories that Python will search when looking for modules to import by inspecting the sys.path.

![sys command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xbo8eornb33joqwwbtba.png)

Any package that you install with Conda will be installed into the directory /usr/local/lib/python3.10/site-packages

So you will need to add this directory to sys.path in order for these packages to be available for import.

![import sys](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rc5aqr8ca6znp9c942dl.png)

![sys opt](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vs8wdam77856ooxesxro.png)

## **# Installing Packages**
Now, install any required package as:

![conda done](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f9a9tb3b45f6nhuf0ak7.png) 

## **Yes! You are done.**