Latest web development tutorials

Python environment to build

This chapter we will show you how to build a Python development environment locally.

Python can be applied to multiple platforms, including Linux and Mac OS X.

You can enter the terminal window "python" command to see if the local version is installed already installed Python and Python.

  • Unix (Solaris, Linux, FreeBSD, AIX, HP / UX, SunOS, IRIX, and so on.)
  • Win 9x / NT / 2000
  • Macintosh (Intel, PPC, 68K)
  • OS / 2
  • DOS (multiple DOS version)
  • PalmOS
  • Nokia mobile phones
  • Windows CE
  • Acorn / RISC OS
  • BeOS
  • Amiga
  • VMS / OpenVMS
  • QNX
  • VxWorks
  • Psion
  • Python can also be ported to the Java and .NET virtual machines.

Python Download

Python latest source code, binary documents, news and other information can be viewed at the official website to Python:

Python's official website:

You can download Python documentation in the following links, you can download the document HTML, PDF and PostScript and other formats.

Python documentation Download:

Python Installation

Python has been ported on many platforms (changed to make it work on different platforms).

You need to download the platform apply to your use of binary code, and then install Python.

If your platform binary code is not available, you need to use C compiler to compile the source code manually.

Compile the source code, there are more functionally selective for python installation provides more flexibility.

The following is the installation of Python on different platforms methods:

Unix & Linux platform installation Python:

The following simple steps to install Python on Unix & Linux platforms:

  • Open WEB browser to access
  • Select the appropriate Unix / Linux source code compression package.
  • Download and extract the archive.
  • If you need to customize some options to modify theModules / Setup
  • ./configure Scriptexecution
  • make
  • make install

After executing the above operation, Python will be installed in / usr / local / bin directory, Python libraries are installed in / usr / local / lib / pythonXX, Python version XX for your use.

Window platform installation Python:

The following simple steps to install Python on a Window platform:

  • Open WEB browser to access
  • Choose Window platform installation package in the download list, the packet formatis:python-XYZ.msi file, XYZ is the version number you want to install.
  • To use the installerpython-XYZ.msi, Windowssystem must support Microsoft Installer 2.0 with use. Just save the installation file to your local computer, and then run it to see if your machine supports MSI. Windows XP and later versions have MSI, many old machines can also install MSI.
  • Once downloaded, double click the downloaded package into Python installation wizard, the installation is very simple, you only need to use the default settings Click "next" to complete the installation.

MAC platform installation Python:

Recent Macs system comes with Python environment, you can also link download the latest version installed.

Environment variable configuration

Procedures and executable files in many directories, and these paths are likely not to provide the operating system search path for executable files.

path (path) is stored in the environment variable, which is named after a string by the operating system maintenance. These variables contain the available information on the command-line interpreter and other programs.

Unix or Windows path variable PATH (UNIX is case-sensitive, Windows is not case-sensitive).

In Mac OS, the installer has changed during the installation path of the python. If you need to refer to Python in a different directory, you must add the Python directory in the path.

In the Unix / Linux environment variable settings

  • In csh shell: input
    setenv PATH "$PATH:/usr/local/bin/python"
    And press "Enter".
  • In the bash shell (Linux): Input
    export PATH="$PATH:/usr/local/bin/python" 
    And press "Enter".
  • In sh or ksh shell: input
    And press "Enter".

Note: / usr / local / bin / python is a Python installation directory.

Setting environment variables in Windows

Add the environment variable Python directory:

At the command prompt box (cmd): Input

Press "Enter".

Note: C: \ Python is Python installation directory.

It can also be set as follows:

  • Right-click on "Computer" and then click "Properties"
  • Then click on the "Advanced System Settings"
  • Select "System Variables" window below the "Path", double-click!
  • And then in the "Path" line, add the path to the python installation (my D: \ Python32), so in the back, add the Remember, the direct path with a semicolon ";" to separate!
  • Finally, after setting success in cmd command line, enter the command "python", you can have associated display.

Python Environment Variables

Here are several important environmental variables, it applies to Python:

variable name description
PYTHONPATH PYTHONPATH is Python search path, we import the default module from PYTHONPATH will find inside.
PYTHONSTARTUP After Python start, first look PYTHONSTARTUP environment variable, and then execute this file variable specifies the code.
PYTHONCASEOK Join PYTHONCASEOK environment variable, it will make the python import module when not case sensitive.
PYTHONHOME Another module search path. It PYTHONSTARTUP or PYTHONPATH directories are usually embedded in the middle, making it easier to switch two module library.

Run Python

There are three ways you can run Python:

1, the interactive interpreter:

You can enter python command line window and open in the interactive interpreter start writing Python code.

You can provide a command line or shell of python coding system in Unix, DOS, or any other.

$ Python # Unix / Linux


C:> python # Windows / DOS

Following is a Python command line parameters:

Options description
-d Display debugging information while parsing
-O Generate optimized code (.pyo file)
-S Find Python path without introducing the position of start
-V Output Python version number
-X After the 1.6 version based on the built-in exceptions (only for strings) is obsolete.
-c cmd Execute Python script, and will run as a result of cmd string.
file Execute python script python in a given file.

2, the command line script

In your application by introducing the interpreter can execute Python scripts from the command line, as follows:

$ Python # Unix / Linux


C:> python # Windows / DOS

Note: When you execute the script, the script is examined executable permissions.

3, the integrated development environment (IDE: Integrated Development Environment)

You can write and run Python code using the graphical user interface (GUI) environment. The following is recommended to use on each platform IDE:

  • Unix: IDLE is the first UNIX Python IDE.
  • Windows: PythonWin is a Python integrated development environment, excellent in many respects than the IDE
  • Macintosh: Python for Mac can use IDLE IDE, you can download on the website of the corresponding MAC IDLE.

Before continuing the next chapter, make sure that your environment is set up successfully. If you can not establish the right environment, then you can help from your system administrator.

Examples are given in later chapters have been tested in Python2.7.6 version.