Below are some important environment variables that apply to Python:
Variable Name | Description |
---|---|
PYTHONPATH | PYTHONPATH is the Python search path. By default, the modules we import are searched in PYTHONPATH. |
PYTHONSTARTUP | When Python starts, it looks for the PYTHONSTARTUP environment variable and then executes the code in the file specified by this variable. |
PYTHONCASEOK | If the PYTHONCASEOK environment variable is set, Python will ignore case sensitivity when importing modules. |
PYTHONHOME | An alternative module search path. It's usually embedded in the PYTHONSTARTUP or PYTHONPATH directory, making it easier to switch between 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 work with Python in Unix, DOS, or any other system that provides a command line or shell.
$ python # Unix/Linux
or
C:>python # Windows/DOS
Below are some Python command-line options:
Option | Description |
---|---|
-d | Display debugging information during parsing |
-O | Generate optimized code (.pyo files) |
-S | Do not import the location to find Python paths on startup |
-V | Output the Python version number |
-X | From version 1.6 onwards, based on built-in exceptions (deprecated for string handling) |
-c cmd | Execute Python scripts and run the result as the cmd string |
file | Execute Python scripts from the specified Python file |
2. Command-Line Script
You can execute Python scripts from the command line by invoking the interpreter in your application, as shown below:
$ python script.py # Unix/Linux
or
C:>python script.py # Windows/DOS
Note: Make sure the script has executable permissions when executing the script.
3. Integrated Development Environment (IDE): PyCharm
PyCharm is a Python IDE developed by JetBrains, supporting macOS, Windows, and Linux systems.
PyCharm features include: debugging, syntax highlighting, project management, code navigation, intelligent suggestions, auto-completion, unit testing, version control, and more...
PyCharm Download Link: https://www.jetbrains.com/pycharm/download/
Professional Edition (Paid): Full-featured, free for a 30-day trial.
Community Edition (Free): A limited version of the Professional Edition.
PyCharm interface:
Install the PyCharm Chinese plug-in, open the menu bar File, select Settings, then select Plugins, click Marketplace, search for Chinese, and then click install to install:
Anaconda Integrated Environment
The Anaconda distribution includes Python.
Anaconda is an integrated environment for data science and machine learning, including the Python interpreter and many commonly used data science libraries and tools.
The management tool for Anaconda packages, dependencies, and environments is the conda command. Compared to the traditional Python pip tool, Anaconda's conda allows for easier switching between different environments and simpler environment management.