Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Python environment construction


May 10, 2021 Python2


Table of contents


Python Environment Building

In this section, we'll show you how to build a Python development environment locally.

Python can be applied to multiple platforms including Linux and Mac OS X, which are already self-afraid, Python-supported, and do not require reconfiguration and installation.

Download the latest version of Python 2.7.9 directly under Windows, and choose when installing

Python environment construction

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

  • Unix (Solaris, Linux, FreeBSD, AIX, HP/UX, SunOS, IRIX, and more). )
  • 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 codes, binary documents, news, and more can be found on Python's website:

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

You can download Python's documents in the links below, and you can download documents in formats such as HTML, PDF, and PostScript.

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 need to download the binary code for the platform you use, and then install Python.

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

The compiled source code is more selective in functionality, providing more flexibility for Python installations.

Here's how to install Python on different platforms:

The Unix and Linux platform installs Python:

Here are some simple steps to install Python on the Unix and Linux platforms:

  • Open the web browser to access http://www.python.org/download/
  • Select the source compression package for Unix/Linux.
  • Download and unzip the compression package.
  • If you need to customize some options to modify Modules/Setup
  • Execute the ./configure script
  • make
  • make install

After doing so, Python is installed in the /usr/local/bin directory, and the Python library is installed in /usr/local/lib/pythonXX, the version number of Python used by XX for you.

Window platform installation Python:

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

  • Open the web browser to access http://www.python.org/download/
  • Select the Window Platform Installation Package in the download list in the format: python-XYZ.msi file, and XYZ is the version number you want to install.
  • To use the installer python-XYZ .msi, the Windows system must support Microsoft Installer 2.0. J ust save the installation file to your local computer and then run it to see if your machine supports MSI. Windows XP and later already have MSI, and many older machines can also install MSI.
  • After downloading, double-click on the download package and go to the Python installation wizard, the installation is very simple, you just need to use the default settings until the installation is complete.

MAC platform installation Python:

Recent Mac systems come with their own Python environments, but come with an older version of Python, and you can view the new features of Python on your MAC at link http://www.python.org/download/mac/.

The full Python installation tutorial on macs 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 likely not in the search path where the operating system provides executable files.

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

The path variable in Unix or Windows is PATH (UNIX case sensitive, Windows case insensescies).

In Mac OS, Python's installation path was changed during the installer process. If you need to reference Python in another directory, you must add python directories to the path.

Set environment variables in Unix/Linux

  • In csh shell: Enter
    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: Enter
    PATH="$PATH:/usr/local/bin/python" 
    , press Enter.

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

Set environment variables in Windows

Add a Python directory to the environment variable:

path=%path%;C:\Python 
Press Enter.

Note: C: .Python is Python's installation directory.

You can also set it up by:

  • Right-click "Computer" and then "Property"
  • Then click "Advanced System Settings"
  • Select Path under the System Variables window and double-click!
  • Then on the Path line, just add the Python installation path (my D: .Python32), so add the path later. n";
  • After the last setup is successful, on the cmd command line, enter the command "python" and you can have a relevant display.

Python environment construction



Python environment variable

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

The name of the variable Describe
PYTHONPATH PYTHONPATH is the Python search path, and by default our import modules are looking for it from PYTHONPATH.
PYTHONSTARTUP After Python starts, look for the PYTHONSTARTUP environment variable and execute the execution code specified by the variable in this file.
PYTHONCASEOK Adding an environment variable to PYTHONCASEOK will make Python case insensive when importing modules.
PYTHONHOME Another module searches for paths. It is typically embedded in the PYTHONSTARTUP or PYTHONPATH directory, making it easier to switch between the two module libraries.


Run Python

There are three ways to run Python:

1, interactive interpreter:

You can go to Python through the command line window and start writing Python code in the interactive interpreter.

You can code Python on Unix, DOS, or any other system that provides a command line or shell.

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

Here are the Python command line parameters:

Options Describe
-d Debug information is displayed at parsing
-O Build optimization code ( .pyo file )
-S The location to find the Python path is not introduced at startup
-v Output Python version number
-X Built-based exceptions (for strings only) have become obsolete since version 1.6.
-c cmd Execute the Python script and use the run results as a cmd string.
file The Python script is executed in a given Python file.

2, command line script

By introducing an interpreter in your application, you can execute Python scripts on the command line, as follows:

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

Note: When executing a script, check that 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 is recommended for IDEs used on each platform:

  • Unix: IDLE is the earliest Python IDE on UNIX.
  • Windows: Python Win is a Python integrated development environment that is in many ways better than the IDE
  • Macintosh: Python's Mac can use the IDLE IDE, and you can download the IDLE for the MAC on the website.

Before you move on to the next chapter, make sure that your environment is successfully built. If you are not able to establish the right environment then you can get help from your system administrator.

The examples given in a later section have been tested in Python 2.4.3 under Centos (Linux).


Run the Python program in Cloud Studio

Python 是跨平台的,它可以运行在 Windows、Mac 和各种 Linux/Unix 系统上。在 Windows 上写 Python 程序,放到 Linux 上也是能够运行的。
要开始学习 Python 编程,首先就得把 Python 安装到你的电脑里。安装后,你会得到 Python 解释器(就是负责运行 Python 程序的),一个命令行交互环境,还有一个简单的集成开发环境。

You can also use Coding Cloud Studio, an online cloud development tool. I t provides a native online Linux command interaction terminal environment, Python run interpreter, online development text editor, you can create Python files directly in your workstation and run your Written Python program in Cloud Studio. Y ou can then skip the rest of this section, such as the installation Python operating environment and the integrated development environment.

Python environment construction

If you're having trouble, you can view the Coding help documentation!