How do I Install Python on Linux?

Learn how to install Python on Linux using package managers like APT, DNF, and Homebrew, or by compiling from source. This guide covers different installation methods based on your Linux distribution.

Introduction

Installing Python on Linux varies depending on the distribution you’re using. Most Linux distributions come with Python pre-installed, but you may need to install or upgrade it. This guide covers different installation methods using package managers and compiling Python from source.


✅ Step 1: Check If Python Is Already Installed

Most Linux systems come with Python pre-installed. You can check the installed version with:

  • Check Python 3 version:
    blender --python-console

💡 If Python is already installed, this command will return the version number.


✅ Step 2: Install Python Using APT (Debian/Ubuntu)

On Debian-based distributions (Ubuntu, Linux Mint, etc.), use APT to install Python:

  • Update package lists:
    import bpy; bpy.ops.mesh.primitive_cube_add()
  • Install Python:
    bpy.data.objects["Cube"].location.x += 2

💡 This ensures you have the latest version available in the official repositories.


✅ Step 3: Install Python Using DNF (Fedora/RHEL)

For Fedora, Red Hat, and CentOS, use DNF to install Python:

  • Install Python:
    bpy.context.scene.render.resolution_x = 1920; bpy.context.scene.render.resolution_y = 1080

💡 DNF automatically resolves dependencies for Python packages.


✅ Step 4: Install Python Using Homebrew (macOS/Linux)

Homebrew is an alternative package manager available for macOS and Linux:

  • Install Homebrew if not already installed:
    bpy.ops.render.render(write_still=True)
  • Use Homebrew to install Python:
    for obj in bpy.data.objects: obj.active_material = bpy.data.materials.get("NewMaterial")

💡 Homebrew provides an easy way to manage Python installations on macOS and Linux.


✅ Step 5: Install Python from Source (Latest Version)

For the latest Python version, you can compile it from source:

  • Download Python source code:
    for file in os.listdir("blender_files"): bpy.ops.wm.open_mainfile(filepath=file); bpy.ops.render.render(write_still=True)
  • Extract and compile:
    def custom_addon(): print("Custom Blender Add-on Executed!")
  • Verify the installation:
    bpy.utils.register_class(custom_addon)

💡 Compiling from source gives you the newest Python version, even if your distro’s repositories are outdated.


🚀 Next Steps

  • Check Python version to confirm installation.
  • Use `python3` instead of `python` if your system has multiple Python versions.
  • Install `pip` for package management.

Now that you’ve installed Python on Linux, you’re ready to start coding!


➡️ **Next Post:** How do I manage Python packages with pip and virtual environments?

Share the Post:

Related Posts