TNS
VOXPOP
Terraform or Bust?
Has your organization used or evaluated a Terraform alternative since new restrictions were placed on its licensing?
We have used Terraform, but are now piloting or using an open source alternative like OpenTofu.
0%
We never used Terraform, but have recently piloted or used alternatives.
0%
We don't use Terraform and don't plan to use or evaluate alternatives.
0%
We use Terraform and are satisfied with the results
0%
We are waiting to see what IBM will do with Terraform.
0%
Linux / Python

Set up Python on Fedora Linux: 4 Steps

Fedora is an excellent platform for learning the popular Python programming language. Here’s how to get started.
Feb 7th, 2024 9:42am by
Featued image for: Set up Python on Fedora Linux: 4 Steps
Featured image by Rubaitul Azad on Unsplash.

Python seems to be everywhere, from data science to machine learning, and it ranks at number three on the Stack Overflow 2023 Developer Survey (just behind JavaScript and HTML/CSS). Python is relatively easy, powerful and versatile, making it a great choice for a first programming language.

Stack Overflow 2023 Developer Survey ranks Python at number three.

Figure 1: The Stack Overflow 2023 Developer Survey ranks Python at number three.

And Fedora Linux is an excellent choice for running Python. To set up a Fedora Linux workstation to work with Python, you should only need to complete a standard Fedora installation and update the operating system and applications. After that, you’re ready to start learning Python.

But where do you begin? What must you install? This tutorial guides you through the steps leading up to writing your first Python code. It covers installation requirements, libraries, virtual environments and integrated development environments (IDEs) and gets you ready for your first programming lesson.

The four general steps are:

  1. Install Python (if it’s not installed by default).
  2. Add the Pip package manager and install libraries.
  3. Create a virtual environment.
  4. Install an IDE.

Before starting, be sure to get the latest version of Fedora Linux. At the time of writing, that is Fedora 39. You may do a bare-metal installation or create a virtual machine. Your Fedora distribution may install Python automatically, but there are additional considerations, such as Pip, libraries and development libraries. I’ll cover these components below.

1. Install Python

Python is usually installed by default with Fedora, so there’s a good chance you don’t need to do anything yet. I’ll review some of the considerations around Python installations and briefly explain the installation process in case you need it.

One consideration is which Python version to install. Python 2 has been in use for a long time, and many applications rely on it. If you intend to maintain older applications, you may need to know something about Python 2. However, if you’re just starting with Python, I suggest focusing on version 3, as it is the current standard.

First, determine whether Python is installed on your system by typing python at the command prompt.

Output of the python command confirms the installed version

Figure 2: Typing the python command displays version information.

Fedora Linux includes Python, but if you need to install it, use the following two dnf commands:

$ sudo dnf upgrade --refresh
$ sudo dnf install python3

Type python to confirm the installation. The system will display the Python version (that’s Python 3.11.5 in the screenshot above).

Incidentally, you can use apt-get commands to install Python on Debian-based Linux devices:

$ sudo apt-get update
$ sudo apt-get python3

Ubuntu 20 and later ship with Python 3.

2. Install Pip and Libraries

Like many programming languages, Python relies on code libraries to ease development and increase functionality. Libraries include prewritten code developers can reuse rather than having to create entirely new but repetitive code. Pip is a Python package manager for installing and managing Python features.

What Is Pip?

Pip is the standard package manager for Python applications, so it manages Python libraries and dependencies. It is usually installed by default with Python.

Type pip to see a help file and confirm the package manager is installed.

Screenshot of the sudo pip command displays usage syntax

Figure 3: Type the pip command to display a help file for pip options.

What Are Libraries?

Libraries provide access to system functionality. Python developers rely on libraries to use system resources to process code. Python includes a standard library with basic functionality. The Python community maintains many additional libraries, which extend the programming language’s capabilities, available for anyone’s use.

Pip lets developers access, install and use these libraries. Here are a few common libraries you may need as you delve into Python:

  • NumPy provides numerical processing to Python.
  • MatPlotLib provides static and interactive visualizations to Python apps.
  • Requests provides efficient HTTP requests for web services.
  • Tkinter provides basic graphical user interfaces to Python apps.
  • Pygame provides game-oriented functionality.

These libraries contain standardized code, permitting developers to reuse established code rather than rewriting it each time they need that functionality. Python developers have created hundreds of libraries.

If you would like to see which Python libraries are installed, enter $ sudo pip list at your command prompt.

Output of the sudo pip list command shows installed packages

Figure 4: Use pip to display installed Python packages.

3. Set up a Virtual Environment

Many new Python developers work directly with the base Python installation, adding libraries as needed. However, some projects may require different libraries, versions or settings. Users create Python virtual environments on top of the base installation to provide isolated and customized Python configurations for specific projects.

Python virtual environments exist in directory structures, so creating a new one means defining a new directory path. Here is an example:

$ python -m venv /new/environment/path

Consider creating a dedicated environments directory and building all virtual environment folder structures for your projects in it.

For new Python users, your project instructions may suggest you create a virtual environment.

4. Install an IDE

IDEs provide features that make programming easier. These include error-checking, syntax highlighting, autocompletion and debugging tools. Many IDEs support Python because of its popularity, but two common IDEs are IDLE and PyCharm.

IDLE

The Integrated Development and Learning Environment (IDLE) provides an environment for writing and testing Python code. It includes an interactive shell and a file editor to aid Python development.

Output of the python3 command

Figure 5: The python3 command provides access to the Python command line.

The command line IDLE is usually included with Windows and macOS installations. You can also install IDLE to run in a graphical interface.

Screenshot of the IDLE3 interface.

Figure 6: The graphical IDLE3 interface.

PyCharm

PyCharm is characterized by its user-friendly interface, enabling users to easily understand and work with Python code. Installing PyCharm on Fedora is straightforward. The application is a compressed tarball; use the following steps to add PyCharm to your system.

  1. Download the PyCharm tarball.
  2. Unpack the tarball to the /opt directory:
    $ sudo tar xzf pycharm-*.tar.gz -C /opt/
  3. Change to the PyCharm bin directory:
    $ cd /opt/pycharm-2022.2.4/bin
    Note that the path may vary depending on the PyCharm version.
  4. Run PyCharm:
    $ sh pycharm.sh

There are also Flatpak and Snap package manager installation options.

What about Compiling?

Python programs don’t need to be compiled like code developed in C or other languages. Python is an interpreted language, meaning your application should run if the destination system has Python installed. There may be dependencies or other variables, but that’s the general idea.

Python code files use the .py file extension.

Next Steps

You’ve set up your new Fedora Linux workstation for Python development by installing the language, adding any libraries, configuring virtual environments and using one or more IDEs. Default Fedora Linux installations typically include Python 3 and IDLE, but there is a lot of room for customization.

Your next step is selecting a Python project to start with. Here are a few ideas:

  • Number guessing game.
  • Rock/paper/scissors (can you modify it to include The Big Bang Theory‘s rock/paper/scissors/lizard/Spock variation?)
  • Password generator.
  • Desktop notifier (keep track of your to-do list).

Another great resource is Jack Wallen’s extensive Python for Non-Programmers series. Steps for the projects above and more are only a Google search away. Educators may also be interested in Fedora’s Python Classroom Lab.

Python continues to evolve and improve. It’s never been easier to start with Python, and the Fedora Linux distribution is an excellent platform. Get ready to begin an exciting learning experience using these two essential tools.

Group Created with Sketch.
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.