Home > Backend Development > Python Tutorial > Example explanation of setting Python environment variables in Windows

Example explanation of setting Python environment variables in Windows

不言
Release: 2018-04-28 10:53:41
Original
2065 people have browsed it

The following is an example of how to set Python environment variables in Windows. It has a good reference value and I hope it will be helpful to everyone. Let’s take a look together

Set environment variables in Windows

Add the Python directory in the environment variables:

In the command prompt box (cmd): Enter

path=%path%;C:\Python
Copy after login

and press "Enter".

Note: C:\Python is the installation directory of Python.

Can also be set in the following ways:

• Right-click "Computer" and then click "Properties"

• Then click "Advanced System Settings"

• Select "Path" under the "System Variables" window and double-click it!

• Then in the "Path" line, just add the python installation path (my D:\Python32), so later, just add the path. ps: Remember, the path is directly separated by a semicolon ";"!

• After the final setting is successful, enter the command "python" on the cmd command line, and the relevant display will be displayed.

Python environment variables

The following are important environment variables, which apply to Python:

Variables Name description

PYTHONPATH PYTHONPATH is the Python search path. By default, the modules we import will be searched from PYTHONPATH.

PYTHONSTARTUP After Python starts, it first looks for the PYTHONSTARTUP environment variable, and then executes the code in the file specified by this variable.

PYTHONCASEOK Adding the PYTHONCASEOK environment variable will make python case-insensitive when importing modules.

PYTHONHOME Another module search path. It is usually embedded in the PYTHONSTARTUP or PYTHONPATH directory, making it easier to switch between the 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 perform python coding work on Unix, DOS or any other system that provides a command line or shell.

$ python # Unix/Linux
Copy after login

or

C:>python # Windows/DOS
Copy after login

The following are Python command line parameters:

Option description

-d Display debugging information during parsing

-O Generate optimized code (.pyo file)

-S Do not introduce the location to find the Python path when starting

-V Output the Python version number

-X Based on version 1.6 or later Built-in exceptions (for strings only) are obsolete.

-c cmd executes the Python script and writes the result as a cmd string.

file Execute a python script in the given python file.

2. Command line script

You can execute Python scripts on the command line by introducing an interpreter into your application, as follows Display:

$ python script.py # Unix/Linux
Copy after login

or

C:>python script.py # Windows/DOS
Copy after login

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

Related recommendations:

Talk in detail about the file path problem of python in windows

The above is the detailed content of Example explanation of setting Python environment variables in Windows. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template