DEV Community

theBridge2
theBridge2

Posted on • Edited on

Python fundamentals (1 of 2): How to install and run python

Installing python

To install python, go to the python downloads page: https://www.python.org/downloads/

To see python version installed, type python -VV in the command line.

To see which version of python you are running and where it is installed in linux:

ls -l $(which python)
Enter fullscreen mode Exit fullscreen mode

Where do I run python?

Once python is installed, you can run python from several places.

Run python with IDLE

When you install python you get the Integrated Development and Learning Environment (IDLE) which is where most beginners start writing programs.

Image description

If you are going to write a program with any complexity however, I would recommend you use an IDE like vs code that allows you to set breakpoints and pause program execution. This is possible in IDLE, but it is fairly rudimentary.

Run python with VS Code

Download vs code from https://code.visualstudio.com/download

Add the python extension to VS Code, by clicking on the extensions side button:

Image description

and searching for python. The correct python package to install is this one:

Image description

Then go ahead and create a hello world python file:

print('hello world!')
Enter fullscreen mode Exit fullscreen mode

Now hit 'F5' to run it in VS Code.

Image description

Select "Python File Debug the currently active python file" and it will run.

This will run in the terminal at the bottom of VS Code.

Image description

Note: if you use break points in vs code and want to see the value of variables or run python commands while the program is paused, go to the debug console at the bottom and start typing away! See below for an example:

Image description

Run python inside a shell

Python shell is created from your command line tool by typing in "python". You are rewarded with '>>>' to indicate you are properly in a python shell.

If this doesn't work for you, and you get an error like this:

Image description

then the problem is that you need to add this to your operating system's path variable.

See part 2 for how to figure out path variable issues. Part 2 - Python Fundamentals: Install packages and dealing with PATH variables

Top comments (0)