Python Environment setup

Source: Internet
Author: User
In this section 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. The general Linux distribution comes with Python,mac OS X The latest version also comes with Python, which is already installed and does not need to be reconfigured.

Download the latest version of the Python 2.7.9 directly under Windows, and when you install it, pay attention to choosing

You can enter the "python" command from the terminal window to see if you have installed Python and the Python installation version locally.

Unix (Solaris, Linux, FreeBSD, AIX, Hp/ux, SunOS, IRIX, etc.). )

Win 9x/nt/2000

Macintosh (Intel, PPC, 68K)

Os/2

DOS (multiple DOS versions)

PalmOS

Nokia Mobile Phone

Windows CE

Acorn/risc OS

BeOS

Amiga

Vms/openvms

Qnx

VxWorks

Psion

Python can also be ported to Java and. NET virtual machines.

Python download

Python's latest source code, binary documents, news, etc. can be found on the Python website:

Python official website: http://www.python.org/

You can download the Python document in the link, and you can download the documents in HTML, PDF and PostScript format.

Python document download Address: www.python.org/doc/

Python installation

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

You will need to download the binary code that is appropriate for your use of the platform, and then install Python.

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

The compiled source code, with more selectivity in functionality, provides more flexibility for Python installation.

Here's how to install Python on different platforms:

Unix & Linux Platform Installation Python:

Here are the simple steps to install Python on UNIX & Linux platforms:

Open a Web browser to access http://www.python.org/download/

Select the source compression package used for Unix/linux.

Download and unzip the zip package.

If you need to customize some options to modify Modules/setup

Execute the./configure script

Make

Make install

After doing this, Python is installed in the/usr/local/bin directory, and the Python library is installed in/USR/LOCAL/LIB/PYTHONXX,XX for the version number of the python you are using.

Windows platform installs Python:

Here are the simple steps to install Python on the Window platform:

Open a Web browser to access http://www.python.org/download/

Select the Window platform installation package in the download list, in the package format: Python-xyz.msi file, XYZ is the version number you want to install.

To use setup Python-xyz.msi, Windows systems must be supported with Microsoft Installer 2.0. 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 already have MSI, and many older machines can also install MSI.

After downloading, double-click the download package, go to the Python Installation Wizard, the installation is very simple, you just need to use the default settings always click "Next" until the installation is complete.

MAC Platform Installation Python:

The most recent Macs system comes with a python environment, but the Python version comes with an older version, and you can view the new features of Python on your Mac via the link http://www.python.org/download/mac/.

Complete Python installation tutorials on Mac You can view: http://www.cwi.nl/~jack/macpython.html

Environment variable Configuration

Programs and executables can be in many directories, and these paths are probably not in the search path where the operating system provides executable files.

The path is stored in an environment variable, which is a named string maintained by the operating system. These variables contain information about the available command-line interpreters and other programs.

Path variable in UNIX or Windows is path (Unix case-sensitive, Windows is case-insensitive).

In Mac OS, the setup process changes the Python installation path. If you need to reference Python in another directory, you must add a Python directory to the path.

Setting environment variables in Unix/linux

In CSH Shell: input
Setenv PATH "$PATH:/usr/local/bin/python", press "Enter".

In bash Shell (Linux): input
Export path= "$PATH:/usr/local/bin/python", press "Enter".

In sh or ksh shell: input
Path= "$PATH:/usr/local/bin/python", press "Enter".

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

Setting environment variables in Windows

To add a Python directory to an environment variable:

In the Command Prompt box (cmd): Enter
Path%path%; C:\Python, press "Enter".

Note: C:\Python is the installation directory for Python.

Python Environment variables

Here are a few important environment variables that apply to Python:

Variable name

Describe

PYTHONPATH PYTHONPATH is the Python search path, and the default import module will be searched from PYTHONPATH.

Pythonstartup python starts, look for the PYTHONSTARTUP environment variable and execute the execution code specified by the variable in this file.

Pythoncaseok joins the PYTHONCASEOK environment variable, it makes Python import the module is not case-sensitive.

Pythonhome another module search path. It is typically embedded in the Pythonstartup or Pythonpath directory, making it easier to switch between two module libraries.

Run Python

There are three ways to run Python:

1. Interactive interpreter:

You can enter Python from a command-line window and start writing Python code in the interactive interpreter.

You can do python coding in unix,dos or any other system that provides a command line or shell.

$python # Unix/linux

C:>python # Windows/dos

The following are the Python command-line parameters:

Options

Describe

-D displays debug information at parse time

-O Generate Optimization code (. pyo file)

-S does not introduce a location to find Python paths when booting

-V Output Python version number

-X is obsolete based on the built-in exception (for strings only) since version 1.6.

-C CMD executes the Python script and runs the result as a CMD string.

File executes the Python script in the given Python file.

2. Command line script

In your application, you can execute a python script on the command line by introducing an interpreter, as follows:

$python script.py # Unix/linux

Or

./script.py # Unix/linux

Or

C:>python script.py # Windows/dos

Note: When executing a script, check to see if the script has executable permissions.

3. Integrated development Environment (ide:integrated development environment)

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

Unix:idle is the earliest Python IDE on UNIX.

Windows:pythonwin is a Python integrated development environment that is superior to the IDE in many ways

Macintosh:python mac can use the idle IDE, you can download the corresponding Mac's idle on the website.

Before proceeding to the next chapter, make sure that your environment has been successfully built. If you are not able to build the right environment, then you can get help from your system administrator.

Examples given in later chapters have been tested in the Python2.7.6 version of Ubuntu (Linux).

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.