Jun 20, 2019 6 min read

Python programming setup guide

Python programming setup guide

Python programming – getting setup depending on which operating system you are running, you will need to use the following guide to set up your programming environment.

For All Systems

I’m going to be objective about which system you might want to consider using as you begin to learn Python, but I will also share my own opinion on the matter. I’ll be objective by being open about the strengths and weaknesses of each system. I’ll be opinionated by letting you know what some good programmers use, and why they use it.

If you don’t already have a favourite text editor for programming, we’re going to use Geany or Sublime Text. These editors make it easy to write and run your programs. There are other editors that many professional programmers prefer, but I want to focus on getting you set up to run your first program and not have to spend time trying to lean about an editor. Unless you have a good reason to use another editor, go ahead and install Geany or Sublime Text on your system.

Linux – Ubuntu

If you already know that you’d like to take python programming seriously, you might want to consider learning to use Linux. The people who build Linux expect you to program at some point, so they’ve built the system to make it as easy as possible to get started.

Most Linux systems already have Python installed, so we’ll just verify that it’s installed, and then install Geany.

Installing Python

Python is probably already installed on your system. To find out if it is installed, open a terminal and type the word python. You’ll probably see output that looks something like this:

$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:38) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

From this output, we can see that Python is installed, and the currently installed version is Python 2.7.6. You’re now running a Python terminal session. You can start typing Python commands here, and you’ll see your output immediately:

>>> print("Hello Python world!")
Hello Python world!
>>> 

To exit the Python session and return to a terminal prompt, enter Control-D.

Python 3

Python 3 is also installed on many newer Linux distributions. To see if you also have Python 3, enter python3 at a terminal prompt:

$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:18) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Installing Python 3

If your system doesn’t have Python 3 installed, you can install it yourself. Here’s how you can get Python 3 running on Ubuntu 12.04:

Add the “deadsnakes” package archive (ppa) to your system. This archive has a number of older and newer versions of Python, including Python 3.4.

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python3.4

Now that Python 3.4 is installed on your system, you have two options. You can start a default Python 2.7 session by running the command ‘python’ in a terminal. You can start a Python 3.3 session by running the command ‘python3.4’ in a terminal.

$ python3.4
Python 3.4.0 (default, Apr 11 2014, 13:05:18) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Installing Geany

Geany is a simple text editor, which makes it easy to run Python programs. Output is displayed in a separate terminal window, which gets you used to working in terminals as well.

  • Open a terminal, and install the package ‘geany’: sudo apt-get install geany
  • Press the windows button, and type ‘geany’.
  • Drag the geany icon to the task bar on the left side of the screen. This creates a shortcut you can use to start geany.
  • Write a Hello World program, and save it as ‘hello.py’.
  • There are three ways you can run a program in Geany:
  • Build > Execute
  • Press F5
  • Click the icon with three gears on it
  • You should see a terminal window pop up, with your output in it:
Hello Python world!


------------------
(program exited with code: 0)
Press return to continue

Configuring Geany to use Python 3

You may have to configure Geany to use Python 3.

Open Geany, and open a Python Hello World program. If you don’t have one on your system, write one and save it as hello.py, and run the program. This makes sure Geany is trying to run Python programs. When you have a running hello.py program, go to Build >> Set Build Commands.

Under ‘Python commands’, look for the ‘Compile’ line. Enter the following in the ‘Command’ box. Make sure you get the spaces right. You should have ‘python3’ followed by a space, and the rest of the command. If you have ‘python 3’, with a space between python and 3, Geany will not be able to run your code.

python3 -m py_compile "%f"

Under ‘Execute commands’, look for the ‘Execute’ line. Enter the following in the ‘Command’ box, paying attention once again to the spaces.

python3 "%f"

Test your setup by running hello.py again.

Windows

Python doesn’t come pre-installed on most Windows computers, but you can download an installer that will set Python up for you. Once you have Python installed and running, it’s pretty straightforward to install Geany, and then configure it to be able to begin your Python programming

Installing Python 3

Since you’re installing Python yourself starting out fresh, it’s a good idea to just install the newest stable version of Python. Most people who still use Python 2 do so because they have to maintain large projects that were originally written for Python 2. Unless you know you’ll have to maintain a large existing project, you’re better off learning Python 3 from the beginning.

The main Python website has a section written just for beginners who are trying to install Python. If you get stuck, take a look at that page and see if anything seems to make sense for your particular system.

Go to the Download page on python.org, and download an installer that’s appropriate for your system. Look for a Python 3.4 installer. It’s helpful to know whether you’re running a 32-bit or 64-bit version of Windows; if you don’t know, download a 32-bit installer. 32-bit installers will work on any system; 64-bit installers will only work on 64-bit systems.

Testing your Python installation

Once Python has finished installing, you’ll want to make sure it’s working. There are several ways to do this.

  • Start Menu > Python (command line) OR Start Menu > Python > Python (command line)
  • This should open up a terminal window, with Python running.
  • Type print("Hello Python world!"), and press Enter.
  • You should see your message displayed back to you in the terminal window.
  • Open a command window (Start Menu > type “command”, and click the black terminal icon)
  • Type C:\Python34\python, and press Enter
  • You should see a Python prompt.
  • Type print("Hello Python world!"), and press Enter.
  • You should see your message displayed back to you in the terminal window.

Installing Geany

Geany is a simple text editor, which makes it easy to run Python programs. Output is displayed in a separate terminal window, which gets you used to working in terminals as well.

  • Go to Geany’s download page.
  • Download the full installer, which is described as Full Installer including GTK 2.16.
  • This is the current direct link to the installer for Geany 1.24.
  • Write a Hello World program, and save it as ‘hello.py’.
  • There are three ways you can run a program in Geany:
  • Build > Execute
  • Press F5
  • Click the icon with three gears on it
  • We should see a terminal window pop up, with your output in it, but you probably won’t see this yet:
Hello Python world!


------------------
(program exited with code: 0)
Press return to continue

You’ll probably see an error message, because Geany doesn’t know where Python lives on your system. We’ll fix that in the next section.

Telling Geany how to find Python

You probably have to configure Geany to tell it how to find the version of Python that you just installed.

Open Geany, and open a Python Hello World program. If you don’t have one on your system, write one and save it as hello.py, and run the program. This makes sure that Geany is trying to run Python programs. When you have a running hello.py program, go to Build >> Set Build Commands.

Python 3

Under ‘Python commands’, look for the ‘Compile’ line. Enter the following in the ‘Command’ box. Make sure you get the spaces right. You should have ‘C:\Python34\python’ followed by a space, and the rest of the command. If you have ‘Python 34’, with a space between Python and 34, Geany will not be able to run your code. Also, make sure your capitalization matches what you see here exactly.

C:\Python34\python -m py_compile "%f"

Under ‘Execute commands’, look for the ‘Execute’ line. Enter the following in the ‘Command’ box, paying attention once again to the spaces.

C:\Python34\python "%f"

Test your setup by running hello.py again.

Python 2

If you installed Python 2.7 instead of Python 3, the commands you want are probably:

C:\Python27\python -m py_compile "%f"

and

C:\Python27\python "%f"

Troubleshooting

If Geany still can’t run your hello.py program, check to see if your installation of Python is somewhere else.

  • Open Windows Explorer.
  • Search for ‘python’.
  • Look for the path to your system’s Python. It is probably something like C:\Pythonxxx\python.
  • If you find it, that is the path you want to use in the above settings.

Your system should now be setup ready for Python programming – have fun!

Please check out my other tutorials:

Install Kali Linux on VirtualBox

Main computer components

Techie Mike
Techie Mike
Self-taught techie, with a passion for computers and all the cool things you can do with them. Techie Mike, B.Eng. B.Sc.
Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Techie Mike - The IT guy in Thailand.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.