DebianLinuxTutorials

How To Install Python 3.7 on Debian 9 Stretch

Install Python 3.7 on Debian 9 Stretch

In this tutorial, we will show you how to install Python 3.7 on Debian 9 Stretch. For those of you who didn’t know, Python is an interpreted, high-level programming language known for its simplicity, readability, and extensive standard library. It has become a go-to choice for many developers due to its versatility and ease of use. While newer versions of Python are available, Python 3.7 remains a popular and stable release, offering a wide range of features and improvements over its predecessors.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of Python 3 on a Debian 9 (Stretch) server.

Prerequisites

  • A server running one of the following operating systems: Debian 9 (Stretch).
  • Familiarity with basic Linux commands will be helpful in navigating the terminal and executing commands.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Python 3.7 on Debian 9 Stretch

Step 1. Before we begin the installation process, it’s crucial to ensure that your system is up-to-date with the latest available packages. Open a terminal and execute the following commands:

sudo apt-get update
sudo apt-get upgrade

Step 2. Installing the Required Dependencies.

To compile Python from its source code, you’ll need to install several development tools and libraries. These dependencies provide the necessary components for building Python and enabling various features. Use the following command to install the required packages:

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget

Step 3. Installing Python 3.7 on Debian 9.

Now we download Python using the following command from the Python official site:

cd /usr/src
wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz
sudo tar xzf Python-3.7.9.tgz

Next, compile Python source code on your system:

cd Python-3.7.9
sudo ./configure --enable-optimizations
sudo make altinstall

 After the installation is complete, you can verify the installed Python version by running:

python3.7 -V

Step 4. Troubleshooting and FAQs

During the installation process, you may encounter some common issues. Here are a few troubleshooting tips and frequently asked questions:

  • ModuleNotFoundError when using pip: If you encounter a ModuleNotFoundError when trying to use pip, it may indicate that some dependencies are missing. Ensure that you have installed all the required dependencies mentioned in Step 2. Additionally, make sure you are using the correct pip version corresponding to your Python 3.7 installation.
  • SSL/TLS errors: If you experience SSL/TLS-related errors, it typically means that the necessary SSL libraries are missing. Double-check that you have installed the libssl-dev package as mentioned in Step 2.
  • Managing multiple Python versions: If you need to manage multiple Python versions on your system, consider using virtual environments. Tools like virtualenv and pyenv allow you to create isolated Python environments with specific versions, ensuring that each project has its own dependencies and avoiding conflicts between different Python versions.
  • Updating Python 3.7: To update your Python 3.7 installation to a newer patch release (e.g., from 3.7.9 to 3.7.10), you can follow the same steps outlined in this article. Download the new source code tarball, extract it, and repeat the configuration, compilation, and installation steps.

Congratulations! You have successfully installed Python. Thanks for using this tutorial for installing Python 3 on your Debian 9 system. For additional help or useful information, we recommend you check the official Python website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button