Table of contents

  1. Install Python 3.7 on Ubuntu 20.04
  2. How to install Python 3.7 on osx-arm64
  3. How to install Python 3.9 on a Linux Ubuntu terminal?
  4. pyenv install: 3.x BUILD FAILED (Ubuntu 20.04 using python-build 20180424)

Install Python 3.7 on Ubuntu 20.04

Ubuntu 20.04 comes with Python 3.8 installed by default. However, if you specifically need Python 3.7, you can follow these steps to install it. Please note that the process might change in the future, so always refer to the official documentation for the latest information.

  • Update the package list and upgrade existing packages:
sudo apt update
sudo apt upgrade
  • Install the necessary dependencies:
sudo apt install software-properties-common
  • Add the deadsnakes PPA, which contains older versions of Python:
sudo add-apt-repository ppa:deadsnakes/ppa
  • Update the package list again:
sudo apt update
  • Install Python 3.7:
sudo apt install python3.7
  • Verify that Python 3.7 has been installed:
python3.7 --version

Now you should have Python 3.7 installed on your Ubuntu 20.04 system. You can use it by calling python3.7 instead of the default python3 command. Keep in mind that Python 3.7 will coexist with the default Python 3.8, so you can use both versions on your system.

Remember that since time has passed, there may have been updates or changes to the process. Always check the official documentation or the PPA's repository for the latest instructions.

How to install Python 3.7 on osx-arm64

Python 3.7 is not officially supported on macOS ARM-based systems (Apple Silicon, M1). Python 3.7 was released before the transition to Apple Silicon, and official Python releases starting from Python 3.8 have included support for macOS ARM64.

If you specifically need Python 3.7 and cannot use a later version, there are some alternative methods you can try, although they are not officially supported and may have limitations:

  1. Use Rosetta 2 (x86_64 emulation): You can run the x86_64 (Intel) version of Python 3.7 using Rosetta 2, which is Apple's translation technology for running x86_64 code on ARM-based systems.

    • Open a Terminal window.

    • Install Homebrew (if you haven't already) by following the instructions at

    • Install Python 3.7 using Homebrew with Rosetta 2 emulation:

      arch -x86_64 /usr/local/bin/brew install python@3.7

    Note that this will install the x86_64 version of Python 3.7, which will run under Rosetta 2 emulation.

  2. Compile from Source: You can try to compile Python 3.7 from the source code on macOS ARM64. This method requires more advanced knowledge and might not work perfectly due to potential compatibility issues.

    • Download the Python 3.7 source code from the Python website:

    • Extract the downloaded tarball and navigate to the extracted directory in the Terminal.

    • Configure and compile Python:

      ./configure --with-openssl=/usr/local/opt/openssl@1.1 --enable-optimizations
      make install

    This method may encounter various issues, and it's not officially recommended.

However, it's essential to consider using a more recent version of Python, such as Python 3.8 or Python 3.9, which have official support for macOS ARM64 and provide better performance and compatibility on Apple Silicon systems. You can install the latest version of Python using Homebrew or other package managers:

brew install python

This will install the latest version of Python, which should be Python 3.9 or later at the time of writing.

How to install Python 3.9 on a Linux Ubuntu terminal?

To install Python 3.9 on a Linux Ubuntu terminal, you can use the apt package manager or compile Python from source. Here's how to do it using apt:

  1. Update Package List: Before installing Python, it's a good practice to update the package list to ensure you have the latest information about available packages. Open a terminal and run:

    sudo apt update
  2. Install Python 3.9: On Ubuntu 20.04 (Focal Fossa) and later versions, Python 3.9 is available in the official repositories. You can install it using the following command:

    sudo apt install python3.9

    If you are using Ubuntu 18.04 (Bionic Beaver), Python 3.9 is not available in the official repositories. In that case, you can use a Personal Package Archive (PPA) to install Python 3.9:

    sudo add-apt-repository ppa:deadsnakes/ppa
    sudo apt update
    sudo apt install python3.9
  3. Verify Installation: After installation, you can check the Python version to confirm that Python 3.9 is installed:

    python3.9 --version

    This should display the Python 3.9 version number.

  4. Set Python 3.9 as Default (Optional): By default, your system may still be using an older version of Python as the default. If you want to set Python 3.9 as the default version, you can use the update-alternatives tool:

    sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1

    You can then use the update-alternatives tool to switch between Python versions if needed:

    sudo update-alternatives --config python3

    Select the Python 3.9 option from the list and press Enter.

With these steps, you should have Python 3.9 installed on your Ubuntu system. Remember to use python3.9 as the command to run Python 3.9 specifically, and python3 to run the default Python 3.x version on your system.

pyenv install: 3.x BUILD FAILED (Ubuntu 20.04 using python-build 20180424)

If you encounter a "BUILD FAILED" error when trying to install a specific Python version with pyenv, it typically means that there are missing dependencies or compilation issues. Here are some steps you can take to troubleshoot and resolve the issue:

  1. Update system packages: Before attempting to install Python, make sure your system is up to date. Run the following commands to update and upgrade your packages:

    sudo apt update
    sudo apt upgrade
  2. Install build dependencies: Python often requires some build dependencies to compile successfully. Install the necessary build tools and libraries:

    sudo apt install build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev \
    libsqlite3-dev llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev
  3. Reinstall pyenv: If you still encounter issues, try reinstalling pyenv to ensure you have the latest version:

    # Uninstall pyenv (if you already have it installed)
    rm -rf ~/.pyenv
    # Reinstall pyenv
    git clone ~/.pyenv
    # Add pyenv to your PATH (add this to your shell configuration file, e.g., ~/.bashrc or ~/.zshrc)
    echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc  # Use ~/.zshrc if you use Zsh
    echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
    echo 'eval "$(pyenv init --path)"' >> ~/.bashrc
    echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
    # Restart your shell or run the following command to apply the changes immediately
    exec "$SHELL"
  4. Install Python with pyenv: After reinstalling pyenv, try installing the desired Python version again:

    pyenv install 3.x
  5. Check for errors and logs: If the installation still fails, pay attention to the error messages and logs provided during the installation process. They can provide valuable insights into the specific issue. Sometimes, the error messages may indicate missing libraries or other issues that need to be addressed.

More Python Questions

More C# Questions