How to Setup Python Development Environment in Ubuntu and Fedora

3 min


This article helps you with the basics and steps to setup your Python development environment in Ubuntu and Fedora. 

Python became popular in the last couple of years due to its powerful libraries, easy syntax, and portability. It is being used currently almost every system across businesses.

So, if you are trying to set up your Python box and wondering how to begin etc., then you are at the right place. Here, I tried to give you some steps to get started.

Setup Python Development Environment in Ubuntu and Fedora

Python Versions

If you are starting up Python development fresh, then it is recommended that you use the latest Python 3.x for your development, as Python 2.x is already out of support. Almost all the leading Linux distributions removed the dependency on Python 2.

If you are running the latest distributions as of today for Fedora or Ubuntu, then you should have Python 3.x already installed and set as the default interpreter. For example, Fedora 37 and Ubuntu 22.04 LTS, which are currently available, have Python 3.11 as the default Python shell.

A quick way to find out what Python version you have is by running the below command from a terminal in both Ubuntu and Fedora.

python2
python3
python3
python3

If you are running earlier versions of Ubuntu or Fedora, then you can install the latest Python 3.x using the below commands:

Ubuntu

sudo apt install python3

Fedora

sudo dnf install python3

Also, run the below command to find out the path of your Python executable in the current system:

which python

Switching Versions as the default interpreter

If your system has multiple Python versions installed – 2.x and 3.x and you want to switch between them, it is possible. 

If you have only one version installed, you can skip this section.

To switch, first, run python from the terminal to find out the default executable path. Ideally, it should be /usr/bin/python. Now, run below to find out the symbolic link to the executable.

ln -l /usr/bin/python
lrwxrwxrwx 1 root root .... /usr/bin/pyhton -> python2

Now check out the $PATH variable to determine the order of path concatenation which the system looks up for executables.

echo $PATH
PATH-Variable
PATH-Variable

As you can see /usr/local/bin is preceding the /usr/bin/ then you can create a soft symbolic link to python3. Then your interpreter should pick up the latest Python 3 instead of Python 2 while running the python command. 

ls -s /usr/bin/python3 /usr/local/bin/python

Now you should logout and log in again to clear any hash entries, or you can run hash -r to clear them out.

Now you can run python from the terminal, and you should have the latest Python 3 picked up.

Python IDE

An integrated development environment (IDE) helps you write and compile and execute your code. There are several free Python IDE available – such as PyCharm, Eclipse, Eric, etc., which you can use. That would be another write-up on their pros and cons. 

If you download Python from the official python.org website, Python accompanies a default development environment called IDLE. IDLE is good for starting up your system, and later you can decide to pick any of the best free Python IDE available.

IDLE is not included in Ubuntu and Fedora along with python as default, you have to install it manually. Run the below commands from the terminal to manually install IDLE.

Ubuntu

sudo apt install idle

Fedora

sudo dnf install python-tools

Once installed, you can launch IDLE from the command line idle or search from the application.

IDLE-environment`
IDLE-environment

Now, you can use IDLE to start your development. Most of the basic options you can find in the File menu of IDLE.

I hope this guide explains what you should know before starting your Python development. Although this guide is primarily targeted to Ubuntu and Fedora, you can still follow the instructions for all Ubuntu and Fedora-based distributions as well. If you are facing problems with the Python environment setup, let me know in the comment section below. 


Arindam

Creator and author of debugpoint.com. Connect with me via Telegram, 𝕏 (Twitter), or send us an email.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

2 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments