Machine Learning 01: Setting up Conda for Ubuntu
I just started on creating a hello-word application on machine learning. First thing had to do was installing python and other required packages. At this time most of the tutorials will guide you to install Anaconda, but they didn’t reveal much details.
So first let’s have a look why do we need this anaconda/conda. Generally python is a massive eco system and has many different versions of libraries used and if you have some experience on programming managing those versions is really cumbersome.
What conda does is it let you create a separate environment to have different versions of python packages together. You can create many different environments that will not share those libraries. So your package installations will be limited to those environments.
This will help us managing many different projects even if they are using different python library versions.
Install Python
Ubuntu has python by default. So you don’t need to install it. you can check the version by
python -V
My version is Python 3.8.3
Install Anaconda
- Click below link and download the package.
https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh
2. Install
Go to the downloaded directory and run following on a terminal.
bash Anaconda3-2020.02-Linux-x86_64.sh
Installation process will prompt for your inputs, having default values are recommended.
Once the installation is completed. Check your installed version number. Mine is conda 4.8.3
conda -V
So we have done the conda installation.
Creating Conda environment
Now we going to use conda what it has been created for. Let’s create a environment.
- Create an environment
conda create -n nuwanPy3 python=3
nuwanPy3: is the name of my environment. it can be your choise
python=3: this is the version number of python we have installed. if your installed python version is 2.7.0 or similar this should be python=2
2. Activate the environment
conda activate nuwanPy3
3. Restart the terminal.
You can verify this setting of environment if you have two versions of python.
You can create many similar environments for different projects and install different library versions as per project requirements.
You can deactivate the environment using conda deactivate nuwanPy3
Installing Python Libraries
I was expecting to have all the libraries required to machine learning when I activate this conda environment. But that is not how its working. It’s just a new empty python environment. You must install all the libraries you need to run a application. What I did was when ever system says some library is missing, installed it with conda install command as following example.
conda install matplotlib
Install SKlearn Python Library
Sklearn is considered as most simplest way to learn machine learning. So let’s install it.
conda install scikit-learn
Tip
It’s better to install whatever library you see as import in your code, using conda install. So less errors happy coding.
Start machine learning
Once you activate the conda environment if you key-in
python
will bring you the python terminal.
Alternative is to use an IDE like pyCharm or any-other will automatically use this conda environment.