Skip to content

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 architecture)
  • Other specialized/niche platforms (OS/2, multiple DOS versions, PalmOS, Nokia mobile phones, Windows CE, Acorn/RISC OS, BeOS, Amiga, VMS/OpenVMS, QNX, VxWorks, Psion)

Additionally, Python can be ported to run within Java and .NET virtual machine environments.


You can find the latest Python3 source code, binary documentation, news, and more on the Python official website.

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

Python3 provides full Chinese documentation: https://docs.python.org/zh-cn/3/


Python has excellent cross-platform compatibility and has been ported to multiple operating systems. It can run stably on mainstream platforms such as Windows, macOS, and Linux.

We recommend downloading the binary installation package for your platform first and quickly completing the installation through a visual wizard or command line — this is the most convenient and efficient approach.

If your operating system does not have a corresponding binary installation package, 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 provides richer feature customization options, making Python environment configuration more flexible.

The following are the download addresses for Python installation packages for each platform:

Source Code can be used for installation on Linux.

The following are methods for installing Python3 on different platforms.

The following are simple steps for installing Python on the Windows platform.

Open a web browser and visit https://www.python.org/downloads/windows/:

These links provide different types of Python installation files suitable for different 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, suitable for embedding into applications.

  • Download Windows embeddable package (32-bit): Embeddable package for 32-bit Windows systems, also suitable 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:

Most Linux distributions come with Python3 pre-installed. If it is not installed or you need to upgrade, you can install it through the package manager.

The following are simple steps for installing Python on Unix & Linux platforms:

  • Open a web browser and visit 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

Using Python3.6.1 as an example:

# tar -zxvf Python-3.6.1.tgz
# cd Python-3.6.1
# ./configure
# make && make install

Open a terminal and run the following commands:

# Update package sources
sudo apt update
# Install Python3 and pip3 (Python package management tool)
sudo apt install python3 python3-pip -y

Open a terminal and run 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 working properly:

# python3 -V
Python 3.6.1

macOS systems come with a Python environment pre-installed. You can download the latest version from https://www.python.org/downloads/mac-osx/.

You can also follow the source code installation method to install.

To verify the Python3 version, open Command Prompt (Windows) or Terminal (macOS/Linux) and run the following command:

# Universal command (recommended, compatible with all systems)
python3 --version
# Additional: On Windows, if PATH is configured, you can also run
python --version

If the output shows something like Python 3.11.4, Python3 is installed successfully.

Verify pip3 (Python package management tool): pip3 is the default package management tool for Python3, used to install third-party libraries. Verification command:

# Universal command
pip3 --version
# Additional Windows command
pip --version

If the output shows something like pip 23.1.2 from xxx (python 3.11), pip3 is available.


If the python command executed successfully above, the environment is configured and no additional setup is needed — this section can be skipped.

The directory where executable files are stored is often not in the system’s default search path. The system’s PATH environment variable (case-sensitive on Unix, case-insensitive on Windows) is used to store the search paths for executable files.

On macOS, if you need to reference Python in a non-default directory, you must manually add the Python installation directory to PATH.

Setting Environment Variables on Unix/Linux

Section titled “Setting Environment Variables on Unix/Linux”

Note: /usr/local/bin/python is the Python installation directory; replace it 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"

If you did not check Add Python.exe to PATH during Python3 installation, the command line will not recognize the python/python3 command. You need to manually configure the environment variables:

  • Find the Python3 installation path (e.g., D:\Python311, C:\Program Files\Python311), and also find the Scripts folder under it (e.g., D:\Python311\Scripts, where pip3 is located).
  • Right-click “This PC” → “Properties” → “Advanced system settings” → “Environment Variables”.
  • Find the Path variable under “User variables” or “System variables” and double-click to edit.
  • Click “New”, add the Python3 installation root path and the Scripts folder path respectively, then click “OK” to save all configurations.

For more detailed configuration instructions, see: https://www.runoob.com/w3cnote/add-python-to-path-on-windows-11.html

Close the existing command prompt, reopen it, and run the verification command for the changes to take effect.

The following are descriptions of several environment variables used with Python:

Environment Variable Core Purpose
PATH The system search path for finding the Python interpreter and executable files
PYTHONPATH The search path for Python to find third-party libraries and custom modules
PYTHONHOME Specifies Python’s installation root directory, telling the interpreter where core/standard libraries are located
PYTHONSTARTUP Specifies the path of a script file to be automatically executed when the Python interactive interpreter starts
PYTHONCASEOK Windows-specific; makes Python ignore case when importing modules
PYTHONDONTWRITEBYTECODE Prevents Python from generating .pyc / .pyo bytecode cache files at runtime

There are three ways to run Python:

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

The following are Python command-line arguments:

Option Description
-d Enable debug mode, displaying detailed debug information during code parsing and interpreter execution
-O Generate optimized code, producing .pyo optimized bytecode files when compiling scripts (ignoring assertion statements and other debug-related code)
-OO Deep optimization of code, generating .pyo files and removing all docstrings from the code to further reduce file size
-S Do not automatically import the site module at Python startup, i.e., do not load configurations related to Python module path lookup (such as the site-packages directory)
-V / –version Output the currently installed Python version number and exit the interpreter directly
-vv Output detailed version information (including compilation environment, dependencies, and other extra information)
-X From Python 1.6 onwards, the usage of built-in exceptions (string-based only) is deprecated; this parameter is for compatibility with older features
-h / –help View the complete help description of all Python command-line arguments and exit the interpreter directly
-c cmd Execute the specified Python code snippet directly on the command line (cmd is a string of code) without writing a .py script file
-m module Run the specified Python module as a module (e.g., pip, http.server, etc.), 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 additional code execution
-b Issue a warning when encountering incompatible comparison operations between bytes and str
-bb Raise an error and terminate the program when encountering incompatible comparison operations between bytes and str
-u Disable the buffering mechanism for standard output (stdout) and standard error (stderr), enabling real-time printing of logs or output content
file Specify the path (absolute or relative) of the Python script file to execute; the interpreter will load and run the code in that file
-q When entering the interactive interpreter, hide the welcome message and directly display the command prompt

You can execute Python scripts on the command line by invoking the interpreter in your application, as shown below:

python script.py

Note: When executing a script, check whether the script has executable permissions.

3. Integrated Development Environment (IDE): PyCharm

Section titled “3. Integrated Development Environment (IDE): 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 suggestions, auto-completion, unit testing, version control…

PyCharm download: https://www.jetbrains.com/pycharm/download/

PyCharm installation: https://www.runoob.com/pycharm/pycharm-install.html

PyCharm interface:


An integrated Python distribution tailored for data science and machine learning, built-in with:

  • Python interpreter
  • Common data science libraries (NumPy / Pandas / Matplotlib, etc.)
  • Environment and package management tool conda

Compared to pip, conda is more suitable for multi-environment switching and is more stable in data science scenarios.

Installation and usage: Anaconda Tutorial

uv Python Package and Environment Management Tool

Section titled “uv Python Package and Environment Management Tool”

uv is a high-speed Python toolchain developed by Astral, built with Rust.

  • High performance: 10~100x faster than pip
  • Dependency management
  • Virtual environment management
  • Python version management

An all-in-one solution that can replace pip, virtualenv, pip-tools, and other tools.

Installation and usage: uv Tutorial

Jupyter Notebook Interactive Computing Tool

Section titled “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
  • Support mathematical formulas (LaTeX)

Notebook files are in JSON format, composed of multiple cells that can mix code and documentation content.

Installation and usage: Jupyter Notebook Tutorial