How to install Python 3 on CentOS, Ubuntu & Debian Cloud Servers

2020-07-06 By Sam 5731 Views linux python development
2 reviews

The Python language is a powerful programming language, and this is a great choice for both beginners and experienced developers. It is commonly used in web development, creating software prototypes and data analysis, etc. Now the Python 3 is the latest version of the Python language.


See the instructions for installing and configuring Python 3 on CentOS, Debian and Ubuntu below.


Start to install Python 3


  1. Before proceeding with the installation of Python, execute the below command to update all the system packages.

    # yum update
    or
    # sudo apt-get update
    

    python1

  2. Once this is done, need to install the following dipantiansess before the python installation.

    # sudo yum -y install yum-utils
    # sudo yum -y install zlib-devel
    # sudo yum -y groupinstall development
    or
    # sudo apt-getinstallbuild-essential libpq-dev libssl-dev openssl libffi-dev zlib1g-dev
    

    python2

    python3

    python4

  3. Start to install python 3 now by using the below commands.

    # wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
    # tar xJf Python-3.6.3.tar.xz
    # cd Python-3.6.3
    # ./configure
    # make
    # make install
    

    python5

    python6

    python7

    python19

    python20

    python21

  4. Check the python version.

    # python3.6 -V
    
    # which python3
    

    python9

    python8

  5. Install pip for managing software packages for Python.

    # sudo yum -y install python36u-pip
    or
    # sudo apt install -y python3-pip
    

    python10

  6. The Pip is used to install and manage programming packages for the development projects. Please find the following syntax.

    # sudo pip3.6 install package_name
    
  7. After that need to install python36u-devel, this provides libraries and header files required for Python 3. Please use the below command to install it.

    python11

    # sudo yum -y install python36u-devel
    or
    # sudo apt install -y python36u-devel
    

    python12


Set Up a Virtual Environment

After the python is installed, you can create your own programming environment with venv option.


  1. Create a new directory for the Python programming environments

    # cd environments
    
    # mkdir environments
    
  2. Create an environment by running the below command.

    # python3.6 -m venv my_env
    

    python13

  3. This command will create a new directory names my_env with that contains the below items using the ll command.

    # ll
    
    bin  include  lib  lib64  pyvenv.cfg
    

    python14

  4. Use the following command to activate the environment.

    # source my_env/bin/activate
    

    python15

  5. The command prompt will now be prefixed with the environment name:

    # (my_env) [root@layerstack environments]#
    

    python16


Testing with a Simple Program


  1. Create a test file using the below command.

    # vi layerstack.py
    

    python17

  2. Add the following contents and save the file.

    print("Hello, Layerstack!!")
    
  3. Run the sample script using the following command.

    # python layerstack.py
    
  4. Output after run this is:

    Hello, Layerstack!!
    

    python18


Related Tutorials

What do you think about this article?

Rate this article
Need assistance?

Try this guide to receive free bundled services at signup on a new free account.

Sign Up

Your Feedback Is Important

We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.