← 返回命令列表

Linux command

python3 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Start an interactive

python3

Execute a Python script

python3 [script.py]

Execute a Python command

python3 -c "[print('Hello')]"

Run a module

python3 -m [module_name]

Start a simple HTTP server

python3 -m http.server [8000]

Install a package

python3 -m pip install [package]

Check Python version

python3 --version

说明

python3 is the interpreter for the Python programming language, version 3.x. It executes Python code either interactively or from script files, supporting both procedural and object-oriented programming paradigms. When invoked without arguments, it starts an interactive REPL (Read-Eval-Print Loop) for experimenting with Python code. With a script file as argument, it executes the script. The -m option allows running installed modules as scripts, enabling functionality like starting HTTP servers, running tests, or managing packages with pip. Python 3 is the current major version of Python, featuring improved Unicode support, print as a function, integer division changes, and many other enhancements over Python 2 (which reached end-of-life in 2020).

参数

-c _command_
Execute Python code passed as a string
-m _module_
Run library module as a script
-i
Inspect interactively after running script
-B
Don't write .pyc bytecode files
-O
Optimize generated bytecode
-OO
Remove docstrings in addition to -O optimizations
-q
Don't print version and copyright on startup
-s
Don't add user site-packages to sys.path
-S
Don't import the site module
-u
Unbuffered binary stdout and stderr
-v
Verbose mode (trace import statements)
-V, --version
Print Python version and exit
-W _arg_
Warning control (error, ignore, always, default, module, once)
-X _option_
Set implementation-specific option
-h, --help
Print help message and exit
-E
Ignore PYTHON* environment variables

FAQ

What is the python3 command used for?

python3 is the interpreter for the Python programming language, version 3.x. It executes Python code either interactively or from script files, supporting both procedural and object-oriented programming paradigms. When invoked without arguments, it starts an interactive REPL (Read-Eval-Print Loop) for experimenting with Python code. With a script file as argument, it executes the script. The -m option allows running installed modules as scripts, enabling functionality like starting HTTP servers, running tests, or managing packages with pip. Python 3 is the current major version of Python, featuring improved Unicode support, print as a function, integer division changes, and many other enhancements over Python 2 (which reached end-of-life in 2020).

How do I run a basic python3 example?

Run `python3` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -c _command_ do in python3?

Execute Python code passed as a string