Python3 Install
# Python3 Environment Setup
## Python3.x Python3 Environment Setup
Python3 has excellent cross-platform compatibility and can run stably on the three major operating systems: Windows, Linux, and Mac OS X. It also supports many other platforms and environments, including:
* Unix series (Solaris, Linux, FreeBSD, AIX, HP/UX, SunOS, IRIX, etc.)
* Legacy Windows systems (9x/NT/2000)
* Classic Macintosh systems (Intel, PPC, 68K architectures)
* Other specialized/niche platforms (OS/2, multiple versions of DOS, PalmOS, Nokia mobile phones, Windows CE, Acorn/RISC OS, BeOS, Amiga, VMS/OpenVMS, QNX, VxWorks, Psion)
Additionally, Python can be ported to run in Java and .NET virtual machine environments.
* * *
The latest Python3 source code, binary documentation, news, and more can be found on the official Python website.
Official Python website: [https://www.python.org/](https://www.python.org/)
!(#)
Python3 provides complete Chinese documentation: [https://docs.python.org/zh-cn/3/](https://docs.python.org/zh-cn/3/)
* * *
## Python Installation
Python has excellent cross-platform compatibility and has been ported and adapted for multiple operating systems, running stably on major platforms like Windows, macOS, and Linux.
We can prioritize downloading the binary installer for the corresponding platform and complete the installation quickly through a visual wizard or command line. This is the most convenient and efficient installation method.
If there is no corresponding binary installer for your operating system, you can obtain the Python source code and manually compile and install it using a C compiler.
Compared to binary package installation, source code compilation offers more extensive customization options for functionality, making Python environment configuration more flexible.
Below are the download addresses for Python installation packages for various platforms:
!(#)
**Source Code** can be used for installation on Linux.
Below are the methods for installing Python3 on different platforms.
### Installing Python on Windows Platform:
Here are the simple steps to install Python on the Windows platform.
Open a web browser and visit [https://www.python.org/downloads/windows/](https://www.python.org/downloads/windows/):
!(#)
These links provide different types of Python installation files, suitable for different types of Windows systems and usage scenarios:
* **Download Windows installer (64-bit)**: Installer for 64-bit Windows systems.
* **Download Windows installer (ARM64)**: Installer for Windows devices with ARM64 architecture.
* **Download Windows embeddable package (64-bit)**: Embeddable package for 64-bit Windows systems, which can be embedded into applications.
* **Download Windows embeddable package (32-bit)**: Embeddable package for 32-bit Windows systems, also for embedding into applications.
* **Download Windows embeddable package (ARM64)**: Embeddable package for Windows devices with ARM64 architecture.
* **Download Windows installer (32-bit)**: Installer for 32-bit Windows systems.
Remember to check **Add Python 3.6 to PATH**.
!(#)
Note: If you do not check **Add Python3.6 to PATH**, the command line will not recognize the python/python3 command, and you will need to manually configure the environment variables.
Press Win+R, type cmd to open the command prompt, and enter python:
!(#)
You can also search for **IDLE** in the Start menu:
!(#)
### Installing Python3 on Unix & Linux Platforms
**Most Linux distributions come with Python3 pre-installed**. If it is not installed or needs to be upgraded, you can install it via the package manager.
#### Source Code Installation
Here are the simple steps to install Python on Unix & Linux platforms:
* Open a web browser and visit [https://www.python.org/downloads/source/](https://www.python.org/downloads/source/)
* Select the source code archive suitable for Unix/Linux.
* Download and extract the archive **Python-3.x.x.tgz**, where **3.x.x** is the version number you downloaded.
* If you need to customize some options, modify _Modules/Setup_
Taking **Python3.6.1** as an example:
# tar -zxvf Python-3.6.1.tgz# cd Python-3.6.1# ./configure# make && make install
#### Ubuntu/Debian
Open the terminal and execute the following commands:
# Update software sources sudo apt update # Install Python3 and pip3 (Python package management tool) sudo apt install python3 python3-pip -y
#### CentOS/RHEL
Open the terminal and execute the following commands:
# CentOS 7 sudo yum install epel-release -y sudo yum install python3 python3-pip -y # CentOS 8/RHEL 8 sudo dnf install python3 python3-pip -y
Check if Python3 is available and working:
# python3 -VPython 3.6.1
### Installing Python on MAC Platform:
MAC systems come with a Python environment pre-installed. You can download the latest version for installation from the link [https://www.python.org/downloads/mac-osx/](https://www.python.org/downloads/mac-osx/).
!(#)
You can also refer to the source code installation method.
### Verifying if the Python3 Environment is Installed Successfully
To verify the Python3 version, open the command prompt (Windows) or terminal (macOS/Linux) and execute the following command:
# Universal command (recommended, compatible with all systems) python3 --version # Supplementary: On Windows, if PATH is configured, you can also execute python --version
If the output is similar to Python 3.11.4, it indicates that Python3 has been installed successfully.
Verifying pip3 (Python package management tool)
pip3 is the default package management tool for Python3, used for installing third-party libraries. Verification command:
# Universal command pip3 --version # Supplementary command for Windows pip --version
If the output is similar to pip 23.1.2 from xxx (python 3.11), it indicates that pip3 is available.
* * *
## Environment Variable Configuration
If the above python command executed successfully, it means the environment is configured and no additional configuration is needed. This section can be ignored.
The directory containing program executable files is often not in the system's default search path. The system's PATH environment variable (case-sensitive on Unix, not case-sensitive on Windows) is used to store the search paths for executable files.
On Mac OS, if you need to reference Python from a non-default directory, you need to manually add the Python installation directory to the PATH.
### Setting Environment Variables on Unix/Linux
**Note:** **/usr/local/bin/python** is the Python installation directory and should be replaced with your actual path.
bash shell (Linux):
export PATH="$PATH:/usr/local/bin/python"
csh shell:
setenv PATH "$PATH:/usr/local/bin/python"
sh/ksh shell:
PATH="$PATH:/usr/local/bin/python"
### Setting Environment Variables on Windows
If you did not check Add Python.exe to PATH when installing Python3, the command line will not recognize the python/python3 command, and you need to manually configure the environment variables:
* Find the Python3 installation path (e.g., D:Python311, C:Program FilesPython311), and also find the Scripts folder under it (path like D:Python311Scripts, where pip3 is located).
* Right-click "This PC" -> "Properties" -> "Advanced system settings" -> "Environment Variables".
* Find the Path variable in "User variables" or "System variables" and double-click to edit.
* Click "New" and add the Python3 installation root path and the Scripts folder path respectively, then click "OK" to save all configurations.
!(#)
Close the original command prompt, reopen it, and execute the verification command for the changes to take effect.
Below are descriptions of several environment variables used with Python:
| Environment Variable Name | Core Function |
| --- | --- |
| `PATH` | The system's search path for finding the Python interpreter and executable files |
| `PYTHONPATH` | Python's search path for finding third-party libraries and custom modules |
| `PYTHONHOME` | Specifies the root installation directory of Python, informing the interpreter of the location of core/standard libraries |
| `PYTHONSTARTUP` | Specifies the path to a script file to be executed automatically when the Python interactive interpreter starts |
| `PYTHONCASEOK` | Windows-specific, allows Python to ignore case when importing modules |
| `PYTHONDONTWRITEBYTECODE` | Prevents Python from generating `.pyc` / `.pyo` bytecode cache files during runtime |
* * *
## Running Python
There are three ways to run Python:
### 1. Interactive Interpreter:
You can enter Python through a command line window and start writing Python code in the interactive interpreter.
You can do Python coding on Unix, DOS, or any other system that provides a command line or shell.
python
Below are the Python command line options:
| Option | Description |
| --- | --- |
| -d | Enable debug mode, displaying detailed debugging information during code parsing and interpreter execution |
| -O | Generate optimized code, creating .pyo optimized bytecode files when compiling scripts (ignoring assert statements and other debugging-related code) |
| -OO | Deeply optimize code, generating .pyo files and removing all docstrings from the code to further reduce file size |
| -S | Do not automatically import the site module when Python starts, meaning it does not load configurations for finding Python module paths (such as the site-packages directory) |
| -V / --version | Output the version number of the currently installed Python and exit the interpreter directly |
| -vv | Output detailed version information (including compilation environment, dependent libraries, and other extra information) |
| -X | Since Python version 1.6, usage based on built-in exceptions (only for string types) is deprecated; this parameter is for compatibility with older related features |
| -h / --help | View complete help documentation for all Python command line parameters and exit the interpreter directly |
| -c cmd | Execute a specified Python code snippet directly in the command line (cmd is a string-formatted code), without needing to write a .py script file |
| -m module | Run a specified Python module (such as pip, http.server, etc.) in module form, automatically finding the module path and executing it |
| -i | After executing the specified Python script, automatically enter the interactive interpreter environment for subsequent debugging and supplementary code execution |
| -b | Issue a warning when an incompatible comparison operation between bytes and str is encountered |
| -bb | Raise an error and terminate program execution when an incompatible comparison operation between bytes and str is encountered |
| -u | Disable buffering for standard output (stdout) and standard error (stderr), enabling real-time printing of logs or output content |
| file | Specify the path to the Python script file to execute (absolute or relative path); the interpreter will load and run the code in that file |
| -q | When entering the interactive interpreter, hide the welcome message and display the command prompt directly |
### 2. Command Line Scripts
You can execute Python scripts in the command line by invoking the interpreter in your application, as shown below:
python script.py
**Note:** When executing scripts, please check if the script has executable permissions.
### 3. Integrated Development Environment (IDE: Integrated Development Environment): PyCharm
PyCharm is a Python IDE developed by JetBrains, supporting macOS, Windows, and Linux systems.
PyCharm Features: Debugging, syntax highlighting, project management, code navigation, intelligent hints, auto-completion, unit testing, version control...
PyCharm Download Address: [https://www.jetbrains.com/pycharm/download/](https://www.jetbrains.com/pycharm/download/)
PyCharm Installation Address: [
Professional (Paid): Full features, with a 30-day trial.
Community (Free): A stripped-down version of the Professional edition.
!(#)
PyCharm Interface:
!(#)
To install the PyCharm Chinese plugin, open the File menu, select Settings, then choose Plugins, click Marketplace, search for "chinese", and click install:
!(#)
* * *
## More Essential Tools
### Anaconda Integrated Environment
A **Python distribution focused on data science and machine learning**, which includes:
* Python interpreter
* Common data science libraries (NumPy / Pandas / Matplotlib, etc.)
* Environment and package management tool `conda`
Compared to `pip`, **conda is better suited for switching between multiple environments** and is more stable in data science scenarios.
Installation and Usage: (#)
### uv Python Package and Environment Management Tool
**uv** is a high-speed Python toolchain developed by Astral, built on Rust.
* High performance: 10-100 times faster than pip
* Dependency management
* Virtual environment management
* Python version management
An all-in-one solution that can replace tools like `pip`, `virtualenv`, `pip-tools`, etc.
Installation and Usage: (#)
### Jupyter Notebook Interactive Computing Tool
A **web-based interactive programming environment** suitable for learning, experimentation, and data analysis.
* Run code and view results in real-time
* Display data visualization charts
* Write Markdown documentation
* Supports mathematical formulas (LaTeX)
Notebook files are in JSON format, composed of multiple Cells, allowing a mix of code and documentation content.
Installation and Usage: (#)
YouTip