We now have a youtube channel. Subscribe!

How to Setup a Python Development Environment

Hello dear readers! Welcome back to another edition of our tutorial on Python. In this tutorial guide, we will be giving you the steps on how to install Python on the different platforms available.

Python is available on wide variety of platforms, including Linux and Mac OS X. Let us discuss on how to set up our Python environment.

Local Environment Setup

Open a terminal window and type python to find out if it is already installed in your system and which version is installed.

The following below are the list of platforms supported by Python -

  • PalmOS
  • Nokia mobile phones
  • Win 9x/NT/2000
  • Macintosh (Intel, 68K, PPC)
  • OS/2
  • DOS (multiple versions)
  • Unix (Solaris, Linus, FreeBSD, IRIX, HP/UX, AIX, SunOS, etc.)
  • BeOS
  • Windows CE
  • Acorn/RISC OS
  • Amiga
  • VxWorks
  • QNX
  • VMS/OpenVMS
  • Psion

Getting Python

You can get the most updated and latest source code, binaries, news, documentations, and so on from the official Python website.

You can also download the Python documentation from the Python website documentation page. The documentation is made available on PDF, HTML and the PostScript format.

Python Installation

Python is made available for a wide range of platforms. You only need to download the binary code that is applicable to your platform and then install.

If the binary code for your platform is not made available, then you need a C compiler to be able to compile the source code manually. Compiling the source code offers more flexibility in terms of choice of features that you would require in your installation.

Below are the simple step by step guide on how to install Python on the various platforms -

Installation on Unix and Linus OS

The following below are the simple steps on installing Python on a Unix/Linus OS -

  • Follow the link to download the zip source code available for Unix/Linus.
  • Download and extract the file from zip.
  • Edit the Modules/Setup file in case you want to customize some options.
  • Run and configure script.
  • make
  • make install

This will install your Python at the standard location /usr/local/bin and it's libraries will be installed at usr/local/lib/pythonXX where XX is the Python's version.

Installation on Windows OS

The following are the simple steps on installing Python on Windows OS -

  • Now follow the link for the windows installer which you see in this format python-XYZ.msi. Download the file into your computer. Note : XYZ is the version you need to install.
  • In order to use this installer python-XYZ.msi, the windows must have full support of the Microsoft installer 2.0. Save the installer file into your computer and run it to find out if the system supports MSI.
  • Run the downloaded file. This will bring up the python install wizard, which is very easy to use. Just accept the default settings, wait until the installation is complete and you are done.

Installation on Mac OS

Recent Macs comes with Python installed, it may be several years out of date. You should visit the official Python site for detailed instructions on how to get the latest version along side with extra tools to support development on Mac. For older Mac OS's before Mac OS X 10.3 (released in 2003), it should be made known that MacPython is available.

Jack Jansen maintains it and you can have full access to the entire documentation at his website. You can find the complete details of installation for Mac installation.

Setting up PATH

Programs and other executable files can be in many directories, so operating systems gives a search path that lists the directories that the OS searches for executables.

The provided path is stored in an environment variable, which is a named string maintained by the operating system. This variable contains information available to the command shell and other programs.

The path variable is named as PATH in Unix and Path in Windows (Unix is case sensitive while on the other hand Windows is not).

In Mac, the installer handles the path details. To invoke the Python interpreter from any of the specific directory, then the python directory must be added to your path.

Setting path at Unix/Linus

To add the python directory to the path for a specific session in Unix -

  • In the csh shell - You have to type the Python setenv PATH "$PATH:/usr/local/bin/python" and press Enter.
  • In the bash shell - You have to type in the PATH export "PATH="$PATH/usr/bin/python" and hit Enter.
  • In the sh or ksh shell - You need to input in the Python PATH="$PATH/usr/bin/python" and hit Enter.
  • Note - /usr/bin/python is the path of the python directory.

Setting path at Windows

To add the Python directory to the path for a particular session in Windows -

At the command prompt - You have to type the following path %path%;C:\python and press Enter.

Note - The C:\Python is the path of the Python's directory.

RECOMMENDED POST: JavaScript Operators

Python Environmental Variables

Following below are the important environmental variables, that are recognized by Python -

Sr.No.Variable & Description
It has a role similar to PATH. This variable tells the Python interpreter where to locate the module files imported into a program. It should include the Python source library directory and the directories containing Python source code. PYTHONPATH is sometimes preset by the Python installer.
It contains the path of an initialization file containing Python source code. It is executed every time you start the interpreter. It is named as .pythonrc.py in Unix and it contains commands that load utilities or modify PYTHONPATH.
It is used in Windows to instruct Python to find the first case-insensitive match in an import statement. Set this variable to any value to activate it.
It is an alternative module search path. It is usually embedded in the PYTHONSTARTUP or PYTHONPATH directories to make switching module libraries easy.

Running Python
There are three different ways to to start Python -
Interactive Interpreter
You can start your Python from Unix, DOS or any other system that provides you a command line interpreter or shell Window.

Enter python in the command line.

Start right away in the interactive interpreter -

$python # Unix/Linux
python% # Unix/Linux 
C:> python # Windows/DOS

Here is the list of all the available command line options -

Sr.No.Option & Description
It provides debug output.
It generates optimized bytecode (resulting in .pyo files).
Do not run import site to look for Python paths on startup.
verbose output (detailed trace on import statements).
disable class-based built-in exceptions (just use strings); obsolete starting with version 1.6.
-c cmd
run Python script sent in as cmd string
run Python script from given file

Script from the Command line
A Python script is executed at the command line by invoking the interpreter on your application, as in the following -

$python script.py # Unix/Linux 
python% script.py # Unix/Linux 
C: >python script.py # Windows/DOS

Note - Be sure the file permission mode allows execution.

Integrated Development Environment
You can as well decide to run your Python program from a Graphical User Interface (GUI) environment, if you have a GUI application on your system that supports Python.

  • Unix - IDLE is the very first Unix IDE for Python.
  • Windows - PythonWin is the very first Windows Interface for Python and is an IDE with a GUI.
  • Macintosh - The Macintosh version of Python is made available from the main website along with IDLE IDE, which is also available for download as MacBinary or BinHex'd files.

If you are not able to setup the environment very well, then you can take help from your system admin. You should make sure that the Python environment is properly set up and working very well.

Note - All examples that we will be giving through out the course of this tutorial on Python will be executed with Python 2.4.3 version

Alright guys! This is where we are rounding up for this tutorial. In our next tutorial, we will be discussing about the Basic Syntax of Python.

Do feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain