Install Python3 and Setup Environment on Ubuntu 20.04

Mahabubur Rahman
0


 

In this tutorial we will discus on installing process of python 3 and its programming environment on ubuntu 20.04.


Step 1: Update and Upgrade 

First of all log on your ubuntu 20.04 os and open terminal, then update and upgrade your system. Then install python3 for ensure latest version of python3.

 $ sudo apt update

$ sudo apt upgrade

$ sudo apt install python3

Step 2: Check Python Version 

Now check the python3 version as following - 

$ python3 -V

You will see the version of installed python3 as bellow -

Python 3.8.5

Step 3: Install pip

To manage/install software packages for python, install pip, it will help to manage package or modules on your python project.

$ sudo apt install python3-pip

Check pip3 version as bellow 

$ pip3 -V

You will see version information as bellow 

pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

You can install package on your python project as bellow

$ pip install your_package_name

Step 4 : Install some essential additional tools 

Now install some additional tools that required for initial development environment.

$ sudo apt install build-essential libssl-dev libffi-dev python3-dev

Step 4 :  Install python virtual environment

The main purpose of Python virtual environment is to create an isolated environment for your python project. That means every project can have its own dependencies, regardless of other projects have. You can install python virtual environment as bellow

$ sudo apt install -y python3-venv

Step 5 :  Create virtual environment

 You can create a virtual environment for your project, that can have some dependencies  required for the project. Every project can have its own virtual environment. You can create virtual environment using venv commend as bellow

$ python3 -m venv env

here we create virtual environment named env you can use any meaningful name for your virtual environment.

Step 6 : Active virtual environment

 Now we will active the virtual environment by writing this commend

$ source env/bin/activate

 After activating virtual environment you will see terminal with prefix virtual environment name

(env) mahabub@mahabub-H110M-DS2V:~$ 

Setp 7 : Test Virtual Environment 

Python interpreter open comment 

(env) mahabub@mahabub-H110M-DS2V:~$ python

Note that, in environment we use python instead of python3 and pip instead of pip3. But outside of environment we mast use python3 and pip3 for python 3.

Then you will see the output as bellow 

 Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Now run commend for print something 

>>> print("Hello world.")

Output

Hello world.

now exit python interpreter as bellow

>>> exit()

Step 8: Deactivate virtual environment  

Now we will deactivate the virtual environment as bellow

$ deactivate



If you have any questions, you can write in the comment box.


Please do not write any irrelevant comments

Post a Comment

0Comments
Post a Comment (0)