Python environment setup
In this chapter we will introduce to you how to set up a Python development environment locally.
Python can be used on multiple platforms including Linux and Mac OS X. General Linux distributions come with Python, and the latest version of Mac OS X also comes with Python, which means it is already installed and does not need to be configured.
Download the latest version of Python 2.7.9 directly under Windows. Please select
when installing. You can enter the "python" command through the terminal window to check whether Python has been installed locally and the installation version of Python.
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 Phones
Windows CE
Acorn/RISC OS
BeOS
Amiga
VMS/OpenVMS
QNX
VxWorks
Psion
Python is also portable to Java and .NET virtual machines.
Python download
Python’s latest source code, binary documents, news information, etc. can be viewed on Python’s official website:
Python official website: http://www.python.org/
You can download it at the link below Python documentation, you can download documentation in HTML, PDF and PostScript formats.
Python document download address: www.python.org/doc/
Python installation
Python has been ported on many platforms (with modifications to enable it to work on different platforms).
You need to download the binary for the platform you are using and then install Python.
If the binary code for your platform is not available, you need to manually compile the source code using a C compiler.
Compiled source code has more selectivity in functions and provides more flexibility for python installation.
The following are how to install Python on different platforms:
Installing Python on Unix & Linux platforms:
The following are simple steps to install Python on Unix & Linux platforms:
Open a WEB browser and visit http://www. python.org/download/
Select the source code compression package for Unix/Linux.
Download and unzip the compressed package.
If you need to customize some options and modify Modules/Setup
Execute the ./configure script
make
make install
After executing the above operations, Python will be installed in the /usr/local/bin directory, and the Python library will be installed In /usr/local/lib/pythonXX, XX is the version number of Python you are using.
Install Python on Window platform:
The following are simple steps to install Python on Window platform:
Open the WEB browser and visit http://www.python.org/download/
Select Window platform installation in the download list Package, the package format is: python-XYZ.msi file, 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. Just save the installation file to your local computer and 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 to enter the Python installation wizard. The installation is very simple. You only need to use the default settings and click "Next" until the installation is completed.
Install Python on MAC platform:
Recent Macs systems all come with a Python environment, but the Python version that comes with it is an old version. You can check the MAC through the link http://www.python.org/download/mac/ Introduction to the new features of Python.
You can view the complete Python installation tutorial on MAC: http://www.cwi.nl/~jack/macpython.html
Environment variable configuration
Programs and executable files can be found in many Directories, and these paths are most likely not in the search paths provided by the operating system for executable files.
path is stored in an environment variable, which is a named string maintained by the operating system. These variables contain information about available command line interpreters and other programs.
The path variable in Unix or Windows is PATH (UNIX is case-sensitive, Windows is not case-sensitive).
In Mac OS, the installation path of python is changed during the installation process. If you need to reference Python from another directory, you must add the Python directory to the path.
Set environment variables in Unix/Linux
In csh shell: Enter
setenv PATH "$PATH:/usr/local/bin/python" and press "Enter".
In bash shell (Linux): Type
export PATH="$PATH:/usr/local/bin/python" and press "Enter".
In sh or ksh shell: Enter
PATH="$PATH:/usr/local/bin/python" and press "Enter".
Note: /usr/local/bin/python is the installation directory of Python.
Set environment variables in Windows
Add the Python directory in the environment variables:
In the command prompt box (cmd): enter
path %path%;C:Python and press "Enter".
Note: C:Python is the installation directory of Python.
Python environment variables
The following are important environment variables, which apply to Python:
Variable name
Description
PYTHONPATH PYTHONPATH is the Python search path. By default, the modules we import will be searched from PYTHONPATH.
PYTHONSTARTUP After Python starts, it first looks for the PYTHONSTARTUP environment variable, and then executes the execution code specified by the variable in this file.
PYTHONCASEOK Adding the PYTHONCASEOK environment variable will make python case-insensitive when importing modules.
PYTHONHOME Another module search path. It is usually embedded in the PYTHONSTARTUP or PYTHONPATH directory, making it easier to switch between the two module libraries.
Running Python
There are three ways to run Python:
1. Interactive interpreter:
You can enter python through the command line window and start writing Python code in the interactive interpreter.
You can do python coding work on Unix, DOS or any other system that provides a command line or shell.
$python # Unix/Linux
C:>python # Windows/DOS
The following are Python command line parameters:
Options
Description
-d Display debugging information during parsing
-O Generate optimized code (.pyo file)
-S Does not introduce the location to find the Python path when starting
-v Output the Python version number
-X Based on built-in exceptions from version 1.6 onwards (only for strings ) is obsolete.
-c cmd Execute the Python script and use the running result as a cmd string.
file Execute python script in the given python file.
2. Command line script
You can execute Python scripts on the command line by introducing an interpreter into your application, as shown below:
$python script.py # Unix/Linux
or
./ script.py # Unix/Linux
or
C:>python script.py # Windows/DOS
Note: When executing the script, please check whether the script has executable permissions.
3. Integrated Development Environment (IDE: Integrated Development Environment)
You can use the graphical user interface (GUI) environment to write and run Python code. The following are recommended IDEs for use on various platforms:
Unix: IDLE is the earliest Python IDE on UNIX.
Windows: PythonWin is a Python integrated development environment, which is better than IDE in many aspects.
Macintosh: Python's Mac can use IDLE IDE, and you can download the corresponding IDLE for MAC on the website.
Before proceeding to the next chapter, please ensure that your environment has been set up successfully. If you are not able to set up the correct environment then you can get help from your system administrator.
The examples given in subsequent chapters have been tested in Python 2.7.6 version under Ubuntu (Linux).

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



VS Code extensions pose malicious risks, such as hiding malicious code, exploiting vulnerabilities, and masturbating as legitimate extensions. Methods to identify malicious extensions include: checking publishers, reading comments, checking code, and installing with caution. Security measures also include: security awareness, good habits, regular updates and antivirus software.

In VS Code, you can run the program in the terminal through the following steps: Prepare the code and open the integrated terminal to ensure that the code directory is consistent with the terminal working directory. Select the run command according to the programming language (such as Python's python your_file_name.py) to check whether it runs successfully and resolve errors. Use the debugger to improve debugging efficiency.

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

VS Code can be used to write Python and provides many features that make it an ideal tool for developing Python applications. It allows users to: install Python extensions to get functions such as code completion, syntax highlighting, and debugging. Use the debugger to track code step by step, find and fix errors. Integrate Git for version control. Use code formatting tools to maintain code consistency. Use the Linting tool to spot potential problems ahead of time.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

Golang is more suitable for high concurrency tasks, while Python has more advantages in flexibility. 1.Golang efficiently handles concurrency through goroutine and channel. 2. Python relies on threading and asyncio, which is affected by GIL, but provides multiple concurrency methods. The choice should be based on specific needs.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.
