How to Setup a Python Environment for Machine Learning?

setup Python environment for machine learning

Are you struggling to set up a Python environment for Machine Learning? By the way, Python is an exciting programming language. But installing it can be a bit tricky for beginners sometimes. 

Virtual Environment for Machine Learning and Deep Learning on MacOS

So here is the guide to you along the way.

The Tools you need to run Python Code

Before installation of python and setup of python Environment, let’s see the python tools, which are used to run python code.

The following tools are used to run python code.

  1. Python Tool
  2. Visual Studio
  3. PyCharm
  4. Sublime Text Editor
  5. Anaconda
  6. Miniconda 
  7. Jupyter Notebook 

You can easily download any of the above from the above-mentioned links. Just install it directly by double-clicking on the downloaded setup. And then follow the instruction up to the finish button.

You can use any of the above to write and run a Python script. However, for Data Analysis, Machine Learning programming, and Deep Learning programming, we have to use Anaconda or Miniconda because 

  1. Firstly, it can be difficult to set up a python machine learning environment on some platforms. 
  2. And secondly, if we need to install a python tool and then install other necessary packages. This can be a confusing task for a beginner user.

Which is better for your computer? Miniconda or Anaconda

Before we start the setup of Miniconda or Anaconda, you have to first understand what would be a good choice for your computer?

  • If you install Miniconda then you don’t need to take care of memory space.
  • On the other hand, for Anaconda, you need a minimum of 5GB of memory space. Otherwise, your computer will not respond. Or your program will not work properly on your computer.

setup Python environment for machine learning

Firstly, let’s see the system requirements of installing Anaconda and Miniconda

System Requirements for Installing Anaconda 

To set up Anaconda on your computer, first, check the following system requirements. 

#1 Operating system

Windows 8 or later, 64-bit macOS 10.13 or later, Linux including Ubuntu, RedHat, CentOS 6 or later.

If your operating system is older, you can find older versions of the Anaconda installers here.

#2 System architecture

Windows- 64-bit x86, 32-bit x86; MacOS- 64-bit x86; Linux- 64-bit x86, 64-bit Power8/Power9.

#3 Space Requirements

Minimum 5 GB disk space is required to download and install. If you have less space, you can install Miniconda instead of Anaconda. The commands are similar for both.

System Requirements for Installing Miniconda

The above system requirement is also applicable to Miniconda excluding memory space.

Python environment setup steps for Anaconda and Miniconda

Before we dive into the python environment setup steps for Anaconda and Miniconda let’s take a look at basic OS procedures.

  • These steps are common for Windows, Mac OS X, and Linux Platforms 
  • But there is only one difference when we use Windows systems. There we need to open a command prompt and write command accordingly 
  • And for Mac OS X or Linux, we need to open a terminal and write commands accordingly.

Download and run Setup For Anaconda- Python Environment for Machine Learning

1. Download Anaconda setup from its website

Download Anaconda Setup

  • Click on Download Button
  • Choose Anaconda 32 bit or 64-bit Installer as per your platform (Windows, OS X, Linux) requirement

Anaconda Installer for Window, MacOs, & Linux

2. Run Anaconda Setup

  • To run Anaconda setup, double click on downloaded Anaconda setup. You may also perform this by right-clicking on setup. Then run it as Run as administrator.

Anaconda Setup Run as administrator

  • Then follow the instruction up to the finish button.

Anaconda3 2020. 11 (64-bit) Setup

Download and Run Setup For Minic

Anaconda3 2020.11 (64-bit) Setup License Agreement

Conda-Python Environment for Machine Learning

1. Download Miniconda setup from its website

  • Open the Miniconda Package link on any browser.

Download and Run Setup for Miniconda

  • Click on the Miniconda Installer link as per your platform (Windows, OS X, Linux).
  • Click on Python version 2 or 3 for 32 bit or 64-bit Installer link as per your platform (Windows, OS X, Linux) requirement

Download Miniconda Windows Installers

Download MacOSX Installers

Download Miniconda Linux Installers

2. Run Miniconda Setup

  • To run Miniconda setup.
  • Double click on downloaded Miniconda setup (or)
  • Right-click on setup and run it as Run as administrator.

Miniconda Setup and Run as administrator

Then follow the instruction up to the finish button. 

Miniconda3 py38_4.9.2 (64-bit) Setup

Miniconda3 Setup License Agreement

Note:
To run setup in Mac OS X or Linux/Ubuntu, we can use the terminal also.

For example, Anaconda installation on Linux/Ubuntu:

  • Anaconda/ Miniconda Running steps For Windows

Anaconda installation on Linux Ubuntu

How to Verify Anaconda / Miniconda Installation

1. Windows

We can check Anaconda / Miniconda Installation on windows in two ways.

  • Open a system command prompt and write the command as conda.
  • Open Anaconda prompt from system menu options by searching anaconda in the search tab.

Window Search box Anaconda prompt

Note: Don’t use Miniconda and Anaconda together. We can check the conda version by writing the command as conda  -V in the system/Anaconda prompt.

2. Mac

We can check Anaconda / Miniconda Installation on Mac in two ways.

  • Open a terminal and write the command as conda.

Anaconda Miniconda Installation on Mac

  • Open spotlight searches and write Anaconda to open Anaconda terminal.

Spotlight Search to open Anaconda Terminal

Note: The steps of windows installation from 3 to 7 is the same for Mac OS X. But only use terminal and spotlight search instead of command prompt and search bar of windows respectively.

3. Linux 

We can check Anaconda / Miniconda Installation on Linux – Ubuntu in two ways.

  • Open application — > System Tools — > Terminal and write command as conda for Linux-CentOS (or)
  • Open Dash by clicking the upper left Ubuntu Icon — > Type terminal and write command as conda for Linux-Ubuntu

Anaconda installation on Linux Ubuntu

  • Then, open the search bar of Linux and write Anaconda to open the Anaconda terminal.

Linux Search bar to open Anaconda Terminal

Note: The steps of windows installation from 3 to 7 is the same for Linux/Ubuntu. But only use terminal and respective search tab instead of command prompt and search bar of windows respectively.

How to Check Anaconda/ Miniconda Package Details

  • We can check Anaconda/Miniconda packages by writing commands as conda list in the system/Anaconda command prompt.

Check Anaconda Miniconda package Details in Command Prompt

How to Update Anaconda and Miniconda

We can confirm the conda environment is up-to-date by writing commands as 

  • conda update conda for miniconda 
  • conda update anaconda for Anaconda

How to Install Additional Python Libraries in Anaconda/Miniconda

We can add any machine learning, deep learning, and data science library file in Anaconda/Miniconda by using two package managers as pip and conda. 

Syntax

To install any additional python libraries by using conda, we use the command as 

  • conda install <library names> (or) 
  • conda install -c anaconda <library file>=<version> in the system/Anaconda command prompt

Example: conda install numpy scipy pandas keras tensorflow scikit-learn 

conda install numpy scipy pandas keras tensorflow scikit

conda install numpy scipy pandas keras tensorflow scikit Command Prompt

How to Remove Libraries in Anaconda/Miniconda

Syntax

To remove any python libraries, we use commands such as conda remove <library name> in the system/Anaconda command prompt.

Example:

conda remove numpy

How to Search Libraries in Anaconda/Miniconda 

To search any python libraries, we use the command as conda search *library name* in the system/Anaconda command prompt.

Example: conda search *numpy*

When some packages aren’t available with conda, we can use pip to install them by writing the command as ‘pip install <library name> in Anaconda Prompt.

Search Libraries in Anaconda Miniconda in Command Prompt

How to Update Libraries in Anaconda Prompt

We can easily update any library file as per our requirements. This can be achieved by writing the below commands in the system/Anaconda prompt.

Syntax:

You can use either of the following

  • conda update <library name> 
  • conda update <library name>=<version>

Example: 

  • conda update scikit-learn
  • conda update scikit-learn=0.18.1

How to Install Jupyter Notebook in Anaconda Prompt

To write a python script, we need a jupyter notebook or any other python text editor. Then launch Jupyter Notebook by installing it. To install it use the command as conda install jupyter notebook in system/Anaconda prompt.

Anaconda Prompt  jupyter notebook

Now, to run Jupyter Notebook Server, open the system/Anaconda prompt again. And write command as jupyter notebook

Anaconda Prompt - Conda install jupyter notebook

(OR)

Search jupyter Notebook at the search bar. Then click on the Jupyter Notebook shell (See below image with a blue arrow).

search jupyter Notebook at search bar

jupyter Notebook in command prompt

After running the server, the jupyter notebook will open in your default browser.

jupyter notebook in browser

You can write your first python program by selecting python 3 at the New dropdown of the jupyter notebook.New droupdown menu in jupyter notebook

Welcome to Python World in Jupyter notebook

Conclusion

Machine learning is often used in search engines. They are used in email filtering to weed out junk and sites to make personalized reviews. Also, in financial tools to spot suspicious purchases. Machine Learning is also present in many applications on various devices, such as speech recognition.

Here, your setup is complete. Now you can enjoy the prospects of Machine learning.

You may also like...

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x