Friday, June 12, 2020

How to Setup a Python Development Environment



Hello guys! Welcome back to another section of my tutorial on Python. In this tutorial post, i will be giving you the steps on how to install Python on the various 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 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, etc. from the official Python website.

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

Python Installation

Python is made available for a wide varieties of platforms. You only need to download the binary code applicable to your own 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 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 now install your Python at the standard location /usr/local/bin and it's libraries will then 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 -

  • Follow the link for the windows installer which you see in this format python-XYZ.msi. Get the file downloaded into your computer. Note : XYZ is the version you need to install.
  • In order to use this installer python-XYZ.msi, the windows system must have full support of the Microsoft installer 2.0. Save the installer file to your computer and then 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 Python installation is complete and you are done.


Installation on Mac OS

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

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

Setting up PATH

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

The path is stored in an environment variable, which is a named string maintained by the OS. 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 Windows is not).

In Mac OS, the installer handles the path details. To invoke the Python's interpreter from any of the particular directory, the python's directory must be added to your path.

Setting path at Unix/Linus

In order to add the python directory to the path for a particular 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 the Python PATH export "PATH="$PATH/usr/bin/python" and hit Enter.
  • In the sh or ksh shell - You will 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

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

At the command prompt - You have to type 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

Here are the important environmental variables, which Python recognizes -

Sr.No.Variable & Description
1
PYTHONPATH
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.
2
PYTHONSTARTUP
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.
3
PYTHONCASEOK
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.
4
PYTHONHOME
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 
or 
python% # Unix/Linux 
or 
C:> python # Windows/DOS

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

Sr.No.Option & Description
1
-d
It provides debug output.
2
-O
It generates optimized bytecode (resulting in .pyo files).
3
-S
Do not run import site to look for Python paths on startup.
4
-v
verbose output (detailed trace on import statements).
5
-X
disable class-based built-in exceptions (just use strings); obsolete starting with version 1.6.
6
-c cmd
run Python script sent in as cmd string
7
file
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 
or 
python% script.py # Unix/Linux 
or 
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 app 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 available from the main website along with IDLE IDE, which is also available for downloades as either  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 i 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 my next tutorial, we will be discussing about the Basic Syntax  of Python. 

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.
Share:

0 comments:

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.