python
Execute Python code
TLDR
Start a REPL (interactive shell)
Execute a specific Python file
Execute a specific Python file and start a REPL
Execute a Python expression
Run the script of the specified library module
Install a package using pip
Interactively debug a Python script
Start the built-in HTTP server on port 8000 in the current directory
SYNOPSIS
python [ -flags ] [ -c command | script | - ] [ arguments ]
PARAMETERS
-c command
Execute the Python code specified as a string command.
script
Execute the Python script specified by the filename script.
-
Read Python code from standard input (stdin).
-d
Turn on parser debugging output (for developers only, depending on compilation options).
-E
Ignore environment variables like PYTHON*.
-h
Display help message and exit.
-i
Enter interactive mode after executing a script.
-m module-name
Run a module as a script.
-O
Optimize generated bytecode slightly.
-OO
Remove doc-strings in addition to the -O optimizations.
-q
Don't print version and copyright messages on interactive startup.
-s
Don't add user site directory to sys.path.
-S
Disable the import of the module site and the site-dependent manipulations of sys.path that it entails.
-u
Force the stdout and stderr streams to be unbuffered.
-v
Verbose output (show import statements, etc.).
-V
Print the Python version number and exit.
-W argument
Warning control; argument is action:message:category:module:lineno.
-x
Skip first line of the source file.
DESCRIPTION
The `python` command typically invokes the Python interpreter. It allows you to run Python scripts, execute Python code directly from the command line, or start an interactive Python session (REPL). The specific version of Python invoked (e.g., Python 2, Python 3) depends on the system configuration and how the `python` command is symlinked. It's crucial to verify the Python version being used, especially when dealing with scripts that have version-specific dependencies. Using virtual environments is a recommended practice to manage Python versions and dependencies for different projects to avoid conflicts.
Note that on many systems, `python` is linked to Python 2, and `python3` is the default way to invoke Python 3. It's essential to be aware of your system's setup.
CAVEATS
The specific Python version invoked by the `python` command may vary across systems. Always verify the version before running scripts with version-specific dependencies. It is best practice to explicitly use `python3` or `python2` to select the correct version.
INTERACTIVE MODE
Running `python` without any arguments will start the interactive Python interpreter, allowing you to execute Python code line by line.
VIRTUAL ENVIRONMENTS
Using virtual environments (created with `venv` or `virtualenv`) is highly recommended to manage project dependencies and Python versions.
HISTORY
Python was initially conceived in the late 1980s by Guido van Rossum. Its implementation began in December 1989. The first version, Python 0.9.0, was released in February 1991. Python 2.0 was released in 2000, introducing list comprehensions and a garbage collection system. Python 3.0, a major and intentionally backwards incompatible release, was released in 2008. The `python` command has been the primary way to invoke the Python interpreter since its inception. The meaning of the command has varied over time depending on the Linux distribution; it either pointed to a Python 2 or Python 3 install. Newer systems try to remove the ambigious `python` symlink and make users specify their Python version.
SEE ALSO
python3(1), idle(1), pydoc(1)