Python Installation - Python: Programming Language for Beginners - Learn In A Day! (2015)

Python: Programming Language for Beginners - Learn In A Day! (2015)

Chapter 2. Python Installation

The up-to-date edition with the binaries, current source codes, documentations, latest news, etc. can be accessed at the official Python website.

Python Official Website: http://www.python.org/

Here, you can download the documentation for Python from the site. It is accessible in various formats like PDF, HTML, and PostScript.

Python Documentation Website: www.python.org/doc/

How to Install Python:

Python is accessible for various platforms. You need to download only the binary code that works fine with the platform and you can install Python after that. If it is unavailable, then use a C compiler that can do manual compilation of the source code. Source code compilation gives you suppleness in terms of features required.

Python Environment Variables:

Variable

Description

PYTHONPATH

It is similar to PATH. This variable foretells the Python interpreter as to where it can locate the module files that you can import in a program. PYTHONPATH must have a Python source library directory and the directories in which your Python code is present. PYTHONPATH is sometimes set by the Python installer automatically.

PYTHONSTARTUP

It has the path for the initialization file which contains Python source codes that are executed each and every time you work on the interpreter. This file is often named .pythonrc.py in Unix, which usually has commands that can load the utilities or can modify the PYTHONPATH.

PYTHONCASEOK

This is used in Windows OS for instructing Python to find case-insensitive matches in an import statement. You can set this to any random value for activating it.

PYTHONHOME

It is an alternative search path that is embedded in PYTHONSTARTUP or PYTHONPATH directories for switching the module libraries very easy.

Running Python

Python can be run on a system in three ways:

Interactive Interpreter:

You can start by entering python and then begin programming in its interpreter by beginning from the command line on any platform that provides a command line interpreter or a shell window.

List of command line options is given in the table below:

Option

Description

-d

Provide the output after debugging

-O

Optimized byte code generation i.e. the .pyo file is generated

-S

Don’t run the import site for searching Python paths in a startup.

-v

Details of import statement

-X

Disable the class based built-in exceptions

-c cmd

It runs python script sent in cmd String

File

Python script is run from the given file.

Script from Command-line: Calling an interpreter on your application can help you run and execute your python script in command line.

Integrated Development Environment: It is possible to run Python from a GUI too. The one thing you require is a system that supports Python.