search

Python environment setup

Nov 23, 2016 am 11:24 AM
python

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

Python environment setup

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).


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Python vs. C  : Learning Curves and Ease of UsePython vs. C : Learning Curves and Ease of UseApr 19, 2025 am 12:20 AM

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

Python vs. C  : Memory Management and ControlPython vs. C : Memory Management and ControlApr 19, 2025 am 12:17 AM

Python and C have significant differences in memory management and control. 1. Python uses automatic memory management, based on reference counting and garbage collection, simplifying the work of programmers. 2.C requires manual management of memory, providing more control but increasing complexity and error risk. Which language to choose should be based on project requirements and team technology stack.

Python for Scientific Computing: A Detailed LookPython for Scientific Computing: A Detailed LookApr 19, 2025 am 12:15 AM

Python's applications in scientific computing include data analysis, machine learning, numerical simulation and visualization. 1.Numpy provides efficient multi-dimensional arrays and mathematical functions. 2. SciPy extends Numpy functionality and provides optimization and linear algebra tools. 3. Pandas is used for data processing and analysis. 4.Matplotlib is used to generate various graphs and visual results.

Python and C  : Finding the Right ToolPython and C : Finding the Right ToolApr 19, 2025 am 12:04 AM

Whether to choose Python or C depends on project requirements: 1) Python is suitable for rapid development, data science, and scripting because of its concise syntax and rich libraries; 2) C is suitable for scenarios that require high performance and underlying control, such as system programming and game development, because of its compilation and manual memory management.

Python for Data Science and Machine LearningPython for Data Science and Machine LearningApr 19, 2025 am 12:02 AM

Python is widely used in data science and machine learning, mainly relying on its simplicity and a powerful library ecosystem. 1) Pandas is used for data processing and analysis, 2) Numpy provides efficient numerical calculations, and 3) Scikit-learn is used for machine learning model construction and optimization, these libraries make Python an ideal tool for data science and machine learning.

Learning Python: Is 2 Hours of Daily Study Sufficient?Learning Python: Is 2 Hours of Daily Study Sufficient?Apr 18, 2025 am 12:22 AM

Is it enough to learn Python for two hours a day? It depends on your goals and learning methods. 1) Develop a clear learning plan, 2) Select appropriate learning resources and methods, 3) Practice and review and consolidate hands-on practice and review and consolidate, and you can gradually master the basic knowledge and advanced functions of Python during this period.

Python for Web Development: Key ApplicationsPython for Web Development: Key ApplicationsApr 18, 2025 am 12:20 AM

Key applications of Python in web development include the use of Django and Flask frameworks, API development, data analysis and visualization, machine learning and AI, and performance optimization. 1. Django and Flask framework: Django is suitable for rapid development of complex applications, and Flask is suitable for small or highly customized projects. 2. API development: Use Flask or DjangoRESTFramework to build RESTfulAPI. 3. Data analysis and visualization: Use Python to process data and display it through the web interface. 4. Machine Learning and AI: Python is used to build intelligent web applications. 5. Performance optimization: optimized through asynchronous programming, caching and code

Python vs. C  : Exploring Performance and EfficiencyPython vs. C : Exploring Performance and EfficiencyApr 18, 2025 am 12:20 AM

Python is better than C in development efficiency, but C is higher in execution performance. 1. Python's concise syntax and rich libraries improve development efficiency. 2.C's compilation-type characteristics and hardware control improve execution performance. When making a choice, you need to weigh the development speed and execution efficiency based on project needs.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor