This guide walks you through installing Python 3.7 on Debian, whether you need it for legacy projects, compatibility with specific libraries, or learning purposes. Debian’s default repositories may not include Python 3.7 (especially on newer releases), so you’ll learn how to add the necessary repository, install the package, and verify the installation.
What You’ll Need
- A Debian system (Debian 10 Buster or later recommended; older versions may lack required dependencies).
- Root or sudo access to install packages.
- An active internet connection to download packages.
- Basic familiarity with the command line.
Step-by-Step
- Update your system
Open a terminal and run:sudo apt updatesudo apt upgrade -y
This ensures your package lists are current and all existing packages are up to date. - Install prerequisite packages
Some tools are needed to add repositories and install software:sudo apt install -y wget build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
These libraries allow Python 3.7 to compile and run with full functionality (e.g., SSL, SQLite, tkinter). - Add the deadsnakes PPA (for Debian)
Debian doesn’t have an official Python 3.7 package in its main repos, but the deadsnakes PPA (Personal Package Archive) provides it. However, deadsnakes is primarily for Ubuntu. For Debian, you can use thedeadsnakesrepository via a script:sudo apt install -y software-properties-commonsudo add-apt-repository ppa:deadsnakes/ppa
Ifadd-apt-repositoryis not available, installsoftware-properties-commonfirst. If the PPA fails (common on Debian), skip to Step 5. - Update package lists again
After adding the repository, refresh your package list:sudo apt update - Install Python 3.7
Now install Python 3.7 and its dev headers:sudo apt install -y python3.7 python3.7-dev python3.7-venv
If the PPA method didn’t work, you can compile from source (see Step 6). - Alternative: Compile from source
If the repository method fails, download and compile Python 3.7.15 (the last 3.7 release):cd /tmpwget https://www.python.org/ftp/python/3.7.15/Python-3.7.15.tgztar -xzf Python-3.7.15.tgzcd Python-3.7.15./configure --enable-optimizationsmake -j$(nproc)sudo make altinstall
Thealtinstallcommand prevents overwriting the system’s defaultpython3binary. This compilation may take 10-20 minutes. - Verify the installation
Check the version:python3.7 --version
You should seePython 3.7.15(or similar). If you used the PPA, you might also havepython3.7in your PATH. - Test pip and venv
Ensure pip is available:python3.7 -m pip --version
If pip is missing, install it with:python3.7 -m ensurepip --upgrade
Create a virtual environment to confirm venv works:python3.7 -m venv test_envsource test_env/bin/activate
You should see(test_env)in your prompt. Deactivate withdeactivate.
Common Mistakes
- Using
python3instead ofpython3.7: The system’s default Python might be 3.9 or newer. Always use the explicitpython3.7command to run your scripts. - Overwriting the system Python: When compiling, using
make installinstead ofmake altinstallcan replace/usr/bin/python3, breaking system tools likeapt. - Missing dependencies: Without the dev libraries (Step 2), compilation may fail or result in a Python without SSL or SQLite support, which causes errors later.
- Forgetting to update after adding PPA: If you skip
sudo apt update, apt won’t see the new packages.
Tips
- Use virtual environments for each project to avoid dependency conflicts. Always create a venv with
python3.7 -m venv myenv. - If you need multiple Python versions, consider using
pyenvto manage them easily. It lets you switch between versions per directory. - For production, stick with the system Python version if possible, as 3.7 is end-of-life (no security updates after June 2023). Use 3.7 only for legacy compatibility.
- When compiling, use
--enable-optimizationsfor better performance, but be aware it increases build time.
Troubleshooting
- “add-apt-repository: command not found”: Install
software-properties-commonwithsudo apt install software-properties-common. - PPA not working on Debian: Debian isn’t officially supported by deadsnakes. If you get errors like “Unable to add PPA”, switch to the source compilation method (Step 6).
- Compilation fails with “No module named ‘_ssl'”: Install the OpenSSL dev package:
sudo apt install libssl-devand reconfigure/rebuild. - pip not found: Run
python3.7 -m ensurepipto install pip. If that fails, downloadget-pip.pyand run it withpython3.7 get-pip.py. - Python 3.7 not found after install: Check if the binary is in
/usr/local/bin(for source install) or/usr/bin(for PPA). Add to PATH if necessary:export PATH=$PATH:/usr/local/bin. - Segmentation fault when running Python: This often indicates a missing or mismatched library. Re-run
ldconfigor rebuild with the dependencies installed.
Frequently Asked Questions
Can I install Python 3.7 on Debian 11 (Bullseye)?
Yes, but the deadsnakes PPA may not work. Compiling from source is the most reliable method. The steps in this guide cover both approaches.
Will installing Python 3.7 break my system Python?
No, if you use altinstall or install from the PPA, it installs as python3.7 and does not replace the default python3. Only make install would overwrite it.
How do I set Python 3.7 as the default for python3?
You can create a symlink: sudo ln -s /usr/local/bin/python3.7 /usr/local/bin/python3, but this may break system tools. Better to use a virtual environment or a version manager like pyenv.
Is Python 3.7 still supported?
No, Python 3.7 reached end-of-life on June 27, 2023. It no longer receives security updates. Use it only for legacy projects that cannot migrate.
Can I use pip with Python 3.7?
Yes, pip works normally. Use python3.7 -m pip install package-name to install packages. Be aware that some modern packages may drop support for 3.7.
What if I need both Python 3.7 and 3.9?
They can coexist. Use python3.7 for 3.7 and python3 for the system version. Virtual environments help keep dependencies separate.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- NFT Listings & Sales Tracker: A Simple Guide
- How to Calculate with Rounded Values in Excel
- iPad Internet Slow? 7 Fixes That Actually Work
- How to Change Mono Audio Settings in Windows 10
- NBA League Pass on LG TV: App or Workaround?
- Disable Automatic Updates in Windows 10: 4 Ways