CentOS Python

Installing Anaconda Python on CentOS 8

Anaconda is a Python distribution designed for data science, machine learning, deep learning etc.  In this article, I am going to show you how to install Anaconda Python 2 and Anaconda Python 3 on CentOS 8. So, let’s get started.

Downloading Anaconda Python:

Anaconda Python is not available in the official package repository of CentOS 8. But, you can easily download it from the official website of Anaconda Python and install on your CentOS 8 machine.

First, visit the official website of Anaconda Python. Once the page loads, click on Download.

Now, click on Download.

You should see the following download page. You can download Anaconda Python 3 (3.7 at the time of this writing) or Anaconda Python 2 (2.7 at the time of this writing) depending on your requirements.

Unless you’ve some specific requirements, you won’t need Anaconda Python 2. You will most likely want Anaconda Python 3.

To download Anaconda Python 3, click on the Download link as marked in the screenshot below.

The same way, you can click on the Download link for Python 2 (2.7 at the time of this writing) in order to download Anaconda Python 2.

Now, select Save File and click on OK.

Your browser should start downloading Anaconda Python installer. It may take a while to complete.

Installing Anaconda Python 3:

In this section, I am going to show you how to install Anaconda Python 3.

First, navigate to the ~/Downloads directory as follows:

$ cd ~/Downloads

Anaconda Python 3 installer Anaconda3-2019.10-Linux-x86_64.sh should be there as you can see in the screenshot below.

$ ls -lh

Now, add executable permission to the Anaconda Python 3 installer Anaconda3-2019.10-Linux-x86_64.sh with the following command:

$ chmod +x Anaconda3-2019.10-Linux-x86_64.sh

As you can see, the Anaconda Python 3 installer script is now executable.

Now, start the Anaconda Python 3 installer as follows:

$ ./Anaconda3-2019.10-Linux-x86_64.sh

Now, press <Enter> to continue the installation.

Now, press the <Space Bar> a few times to go to the end of the license agreement.

Once you’re at the end of the license agreement, you should see the following prompt.

Type in yes and press <Enter> to accept the license agreement.

Now, type in a directory where you want to install Anaconda Python 3. The default installation location is ~/anaconda3 (in your HOME directory).

Once you’re done, press <Enter>.

Anaconda Python 3 is being installed. It may take a while to complete.

Once Anaconda Python 3 is installed, you will be asked whether you want add Anaconda Python 3 to the PATH or not.

Type in yes and press <Enter> to add Anaconda Python 3 to the PATH.

Anaconda Python 3 should be added to the PATH.

Now, close the Terminal and open a new one for the changes to take effect.

Now, run the following command to verify whether Anaconda Python 3 is accessible.

$ conda --version

As you can see, I can access Anaconda Python commands. So, it’s working.

In order to use Anaconda Python 3, all you have to do is to use the python3 interpreter to run your program.

$ python3 path/to/python3-script

But, in order to confirm that the python3 interpreter is indeed the Anaconda version of Python 3, start the Python 3 interactive shell as follows:

$ python3

It should show you Anaconda, Inc. on linux as marked in the screenshot below. So, it is the Anaconda version.

Now, press <Ctrl> + D or type in exit() and press <Enter> to exit out of the Python 3 interactive shell.

You can also access your normal Python 3 interpreter (that comes with CentOS 8 by default).

Type in python3 and press <Tab> twice. You should see a list of all your Python 3 interpreters.

Here, python3, python3.7 and python3.7m interpreters are from Anaconda Python 3. You can use any of them to start Anaconda Python 3.

python3.6 and python3.6m interpreters are the CentOS 8 defaults. These are not from Anaconda Python 3.

To confirm that python3.6 and python3.6m interpreters are indeed the CentOS 8 defaults, start the Python 3 interactive shell using python3.6 command as follows:

$ python3.6

Red Hat 8.x.y-z on linux should be printed on the screen as you can see in the screenshot below.

So, you can run a Python script with Anaconda Python 3 as follows:

$ python3 path/to/python3-script

You can run a Python script with normal Python 3 interpreter as follows:

$ python3.6 path/to/python3-script

Installing Anaconda Python 2:

You can install Anaconda Python 2 the same way. Just download the Anaconda Python 2 installer and follow the same steps as Anaconda Python 3 installation.

First, navigate to the ~/Downloads directory as follows:

$ cd ~/Downloads

Anaconda Python 2 installer script Anaconda2-2019.10-Linux-x86_64.sh should be there.

$ ls -lh

Now, add executable permission to the Anaconda Python 2 installer script Anaconda2-2019.10-Linux-x86_64.sh as follows:

$ chmod +x Anaconda2-2019.10-Linux-x86_64.sh

Now, start the Anaconda Python 2 installer as follows:

$ ./Anaconda2-2019.10-Linux-x86_64.sh

Now, press <Enter> to continue.

Press <Space Bar> a few times.

Now, type in yes and press <Enter> to accept the license agreement.

Type in a directory path if you want to change the default installation path ~/anaconda2.

Once you’re done, press <Enter>.

Now, type in yes and press <Enter> to add Anaconda Python 2 to the PATH.

Anaconda Python 2 should be installed.

You can access Anaconda Python 2 interactive shell as follows:

$ python2

As you can see, it is the Anaconda version of Python 2.

You can run a Python script with Anaconda Python 2 as follows:

$ python2 /path/to/python_script

So, that’s how you install Anaconda Python 2 and Anaconda Python 3 on CentOS 8. Thanks for reading this article.

About the author

Shahriar Shovon

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.