Install Python and configure the work environment on Linux

08-11-22 Ahmed Obaid 4245 0



In this article, we will learn how to install Python on Linux and how to work with it. Follow the explanation and start writing Python code in a jiffy!

You are here in the right place. To become a Pythoneer or Pythonista, or a Python programmer.

Requirements for installing Python on Linux

You will need some prerequisites that must be met before we can install Python on Linux. They are as follows:

Computer running Debian/Fedora with minimum 2GB of RAM (4GB recommended) and 5GB of disk space

Also, you need to have sudo access on the system where you want to install Python

Note: The sudo command is a command that allows you to upgrade the normal user account to a super user account in order to obtain root privileges.  Learn more about sudo commands 

How to check the version of Python on Linux?

Python comes preloaded with many Linux distributions, but it may be an outdated version. You should check the version on your system.

To see the Python versionundefined you have, open a terminal window and try the following commands: 


# Check the system Python version
 $python --version

 # Check the Python 3 version
 $python3 --version

 # Check the Python 2 version
 $python2 --version

For example, if you already have it installed on your system, you'll see a result similar to this:


 $python3 --version
 Python 3.6.10

 How to download and install Python on Linux

Step 1: Install the development packages required to build Python:

 On Debian:


 $ sudo apt update
 $ sudo apt install build-basic zlib1g-dev \
 libncurses5-dev libgdbm-dev libnss3-dev \
 libssl-dev libreadline-dev libffi-dev curl

 In Fedora:


$ sudo dnf groupinstall development

 Step 2: Download the latest stable version of Python 3:

 Visit  and download the latest version of Python 3. After the download is complete, you will have a .tar.xz ("tarball") archive file containing the Python source code.

 Step 3: Extract the tar file to install Python on Linux:

 Once the download is complete, extract the tarball either using the extractor app of your choice or the Linux tar command, undefined for example:


$ tar -xf Python-3.?.?.tar.xz

 Step 4: Configure the Script:

 Once you've extracted the Python ball, go to the configuration script and execute it in the terminal with:

 


$ cd Python-3.*
 ./configure

 Configuration may take some time. Wait for it to finish.

 Step 5: Start the build process:

 If you already have a version of Python installed on your system and want to install the new version alongside it, use this command:


 $ sudo make altinstall

 If you want to replace the current version of Python with this new one, you have to uninstall the current Python package using a package manager (such as apt or dnf ) and then install:


 $ sudo make install

 Step 6: Verify the installation:

 If you haven't encountered any errors, your Linux system will now have the latest version of Python installed. To check this, type one of these commands in the terminal:


 python --version

 Create a virtual environment (optional)

Python provides a package known as venv (virtual environment), which helps you isolate a directory or program package from others.

 To create a virtual environment, enter what undefined The following is in the terminal (in this example, I assume the version of Python you have installed is 3.8):

 


python3.8 -m venv example

 This command creates a new directory (which I named example ), with some subdirectories.

 To activate the virtual environment, enter:


 $ source example/bin/activate
 (example) $

 Note that the terminal command prompt ($ ) is now preceded by the name of the default environment.

 To deactivate the virtual environment, use the deactivate command:


 (example) $ deactivate

more information:

You may wish to refer to the following resources for additional information on this topic.

Documenting Python: Creating a Virtual Environment

Conclusion:

You can now access the latest version of Python for your system. Your journey in learning Python is just beginning.

In this lesson you learned how to:

Check which version of Python is installed on your system, if any

We learned how to install the latest version of Python on Linux

We created the working environment

If you have any feedback or questions, please leave them in the comments.



Tags


Python linux

Share page