Official Power Up Hosting Blog

Everything about Linux, Windows, and hosting ;)

Selvakumar
Author

I am an Online Marketer and technology lover. I like to learn new things and share that with people.

Share


Our Newsletter


Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Tags


Twitter


Official Power Up Hosting Blog

How To Install Anaconda Python on Ubuntu 16.04 [Command Line]

SelvakumarSelvakumar

Do you want to use Anaconda Python on your Ubuntu Server?

Is the installation process confusing and preventing you from enjoying the features of Anaconda Python?

Don't worry.

Here is the step by step installation process for you to install Anaconda Python on your Ubuntu Server smoothly.

First Let us see What Anaconda Python is.

install anaconda python ubuntu

What is Anaconda Python?

Anaconda is the freemium open source distribution of Python and R Programming Languages.

Anaconda is used for Scientific computing which involves heavy calculations, High Scale data processing and predictive analysis.

Who are all using Anaconda Python?

Anaconda Python is used by Data scientist, business analyst, and software developers.

Anaconda Python has totally 720 packages, and they are both free and paid.

Anaconda Python has the package management system called Conda.

Look:

We are going to use command line interface(Terminal) in Ubuntu.

Now:

In this anaconda python tutorial, let us see how to install anaconda Python on Ubuntu 16.04.

Prerequisites

Here are the requirements which you should have to install Anaconda Python.

1.You should have the Ubuntu version of 16.04 and also
2.The non-root user with sudo privileges for your server

Next:

we are going to install anaconda Python using below mentioned commands.

Installing Anaconda

Anaconda Python Installation involved only three steps. The steps are

  1. Download the Anaconda installer bash script, i.e., anaconda python install package(Latest Version)
  2. Verify the downloaded script
  3. Run the Script

Here is how we are going to implement these steps.

Step 1

To process anaconda python download go here

Note: Always try to use the latest version.

As of now:

Anaconda 4.3.0 is the latest version.

But I am going to use version 4.2.0 for the demonstration:

The next step is to use the tmp directory on the server.

Why we use tmp directory here?

The reason is simple. It is to save memory.

Once you installed the Bash Script, you don't need it anymore.

Now:

Change the directory to tmp.

$ cd /tmp

Now it's time for downloading the bash script.

Use curl to download the file.

You should copy the URL of the file(Bash Script) from Anaconda Python website.

Paste the URL in front of curl command and run it.

$ curl -O https://repo.continuum.io/archive/Anaconda3-4.2.0-Linux-x86_64.sh

The next step:

You have to verify the data integrity using cryptography hash verification via the SHA-256 checksum.

Here is the command for that.

$ sha256sum Anaconda3-4.2.0-Linux-x86_64.sh

The output will look like this.

Output:
        73b51715a12b6382dd4df3dd1905b531bd6792d4aa7273b2377a0436d45f0e78  Anaconda3-4.2.0-Linux-x86_64.sh

Next part is comparison:

You have to match the output with the hashes mentioned at this page

There are a row sha2561.

Your output should match the hash value mentioned there.

After that, you can proceed further.

Now:

To initialize the installation process, Execute the following code.

$ bash Anaconda3-4.2.0-Linux-x86_64.sh

You will get the following output.

Output:

Welcome to Anaconda3 4.2.0 (by Continuum Analytics, Inc.)

To continue the installation process, please    review the license
agreement.
Please, press ENTER to continue

Press enter two times.

Now the license agreement will be there.

Read the license agreement( I know you won't :)).

after that, you will be asked to approve the license term.

Do you approve the license terms? [yes|no]

Then type Yes.

Look:

First, you should set location for installation.

You can use the default location for the installation or specify a location of your choice to install.

Output
Anaconda3 will now be installed into this location:
/home/sammy/anaconda3

- Press ENTER to confirm the location
- Press CTRL-C to abort the installation
- Or specify a different location below

[/home/sammy/anaconda3] >>> 

The Installation process starts now:

The installation process takes place and it will take some time to finish.

The Anaconda Python will be installed on your specified location.

Once the installation is complete, you will get the below output.

Output
...
installation finished.
Do you wish the installer to prepend the Anaconda3     install location
to PATH in your /home/sammy/.bashrc ? [yes|no]
[no] >>> 

To use the conda command utility, type yes and you will get the following output.

Output
Prepending PATH=/home/sammy/anaconda3/bin to PATH in    /home/sammy/.bashrc
A backup will be made to: /home/sammy/.bashrc-anaconda3.bak
...

To activate the installation, execute the code below.

$ source ~/.bashrc

Now you have to verify the installation using the conda command.

$ conda list

Look at the output:

The output will list all the anaconda python packages you have.

Output
# packages in environment at /home/sammy/anaconda3:
#
_license                  1.1                          py35_1  
_nb_ext_conf              0.3.0                    py35_0  
alabaster                 0.7.9                    py35_0  
...

Now, we have verified that the anaconda python is installed.

Our next step is to setup the environment for anaconda.

Setting Up Anaconda Environment

One more step:

To keep all your projects organized, the Python helps you by using the anaconda virtual environment.

You can select which version of Python is needed for your anaconda python environment.

You can keep all the relevant programming files in the same directory.

Now, let us check the available version of Pythons for use by executing the command.

$ conda search "^python$"

The output will contain multiple versions of Python including Python 2 and Python 3.

Here:

In this tutorial, we are using Python version 3. Now you have access to python 3 packages.

We are going to create an environment using the Python 3 by assigning version 3 to the Python argument.

Let us name the environment as my-env.

But you can use any name especially when you are using the environment to access more than one version of python.

Execute the command line

$ conda create --name my_env python=3

The result of the executed command will have the information about what are all downloaded and which packages will be installed.

If you agree, then Press Y to continue.

Next:

To activate the newly created environment use the command below.

$ source activate my_env

Once the environment is set, the prefix of the command prompt will change to the environment name.

(my-env) [email protected]:~$

Now:

You can verify the version of python which you want to use.

(my-env) [email protected]:~$  python --version

The output will look like this

Python 3.6.0 :: Continuum Analytics, Inc.

How to deactivate Anaconda environment?

Execute the command If you want to deactivate your anaconda environment,

(my-env) [email protected]:~$ source deactivate

You can use both .( dot operator) or source in the above command which will return the same result as above.

If you want to use the specific version of Python, you should pass the exact version to the Python argument.

Here the argument will receive the latest version number.

For example:

I want to use version 3.5.

Follow the command syntax below and replace the number at the end with your required version of Python.

$ conda create -n my_env35 python=3.5

If you want to update your version of Python in your environment, you can use the below command.

For e.g., updating from version 3.5.1 to 3.5.2

(my-env) [email protected]:~$ conda update python

If you want to use Python Version 3.3.2, just pass it to the argument.

Now:

You can check all the environment you have created using the below command.

$ conda info --envs

The output will be like

Output
# conda environments:
#
my_env                      /home/sammy/anaconda3/envs/my_env
my_env35                    /home/sammy/anaconda3/envs/my_env35
root                  *  /home/sammy/anaconda3

The Asterisk symbol(*) in front of the environment represents the current environment.

The environment you create using conda create will have default packages.

Here is how to add additional packages:

We are going to add some additional package(numpy) with the following command.

$ conda install --name my_env35 numpy

You can also add the anaconda numpy package using the conda create command by targeting it.

$ conda create --name my_env python=3 numpy

If you finished all the project works and no need of environment, you could simply remove it using the command.

$ conda remove --name my_env35 --all

When you check for the environment list using conda info --envs, the environment you removed won't be listed there.

Updating Anaconda

You have to frequently check for the latest version of Anaconda so that you can use that current version and its packages.

Execute the below command.

 $ conda update conda

The prompt will ask of Yes or no, type y to proceed.

Now you can make sure that you are using the latest version of both conda and anaconda.

Uninstalling Anaconda

If you are not using anaconda and want to remove it, you can use the anaconda-clean module to remove the anaconda configuration files when you are uninstalling.

$ conda install anaconda-clean

Type y to install the anaconda clean module.

Next Step:

It will ask Y every time to remove each package. Type y and proceed.

To avoid typing y every time, type --yes at the end of the comment.

It won't ask your permission anymore and removes the packages.

anaconda-clean

The command execution also creates a backup file in the home directory.

Output
Backup directory: /home/sammy/.anaconda_backup/2017-01-   25T191831

To remove the entire anaconda directory use the below command.

rm -rf ~/anaconda3

Now:

We have to remove the path line from .bashrc.

Open nano to do that.

$ nano ~/.bashrc

The file will open and you have to remove the line added by anaconda.

/home/sammy/.bashrc
# added by Anaconda3 4.2.0 installer
export PATH="/home/sammy/anaconda3/bin:$PATH"

Remove the path and Press CTRL+X *to exit and press *Y to save.

The removing process is finished now. The Anaconda is removed from the server.

Conclusion

In this anaconda python installation tutorial, we have seen

  1. how to download and install anaconda
  2. Using conda commands
  3. creating environments
  4. changing the Python Version
  5. Updating the Anaconda
  6. Remove the anaconda from the server.

Hey, You also learned how to use anaconda commands :)

Anaconda is widely used for large-scale data processing and helps many organizations and professionals who play with data.

If you still have doubts, let us know that via comments. We are happy to help you.

Selvakumar
Author

Selvakumar

I am an Online Marketer and technology lover. I like to learn new things and share that with people.

Comments