Set up Python Dev Env on Linux (Newbie)

This article shows how one can setup simple python environment on a Linux machine, but does not go into virtual environment, poetry, or pypi setup. It’s meant for beginners to get started on experimenting python quickly.

There are a few steps I took to set up my python dev env (shorthand for Development Environment):

  • install python
  • install pip
  • download VSCode
  • purchase and install PyCharm (optional, but highly recommend for those who work with python extensively, especially professionally)

Install or Update Python

Install

On a typical Linux install, python may already have been installed. You can check by opening a new terminal, and type

$ python3 --version
Python 3.10.12

Or you can simply type python if there are no python2 installed on your machine:

$ python --version
Python 3.10.12

If python is not already installed, you can install it

  • Debian/Ubuntu
sudo apt-get install python3
  • Fedora/CentOS/RedHat(RHEL)
sudo yum install python3

Update

To update python

  • Debian/Ubuntu
$ sudo apt-get update && sudo apt-get upgrade python3
  • Fedora/CentOS/RedHat(RHEL)
$ sudo yum update python3

Install and Setup PIP

Install Pip

  • All Linux
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python3 get-pip.py 
  • Debian/Ubuntu
$ sudo apt-get update
$ sudo apt-get install python3-pip
  • Fedora/CentOS/RedHat(RHEL)
$ sudo yum install python3-pip 

Verify install (pip3 or pip, if there are no older python2 installs on your machine)

$ pip3 --version
pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)
$ pip --version
pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)

Create a Simple Hello Python App

To verify that you are ready to develop in python, you can create a hello.py file as followed:

print ("Hello Python")

and run it (let’s run ls to make sure that the file exists in the same directory)

$ ls
hello.py
$ python hello.py
Hello Python

Let’s create another a tiny bit more complex program (make sure the indentations are in tabs) called hello_function.py

def print_hello():
     print("Hello Python from a function")

if __name__ == '__main__':
    print_hello()

and run

$ ls 
hello.py    hello_function.py
$ python hello_function.py
Hello Python from a function

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply