An example of setting the Python environment variable in Windows

  • 2020-08-22 22:15:00
  • OfStack

Set the environment variable in Windows

Add the Python directory to the environment variable:

In the command prompt box (cmd) : Type


path=%path%;C:\Python

Press the "Enter".

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

You can also set it this way:

The & # 8226; Right click on computer and then click on Properties

The & # 8226; And then I'll go to Advanced System Settings

The & # 8226; Select "Path" under the "System Variables" window and double-click!

The & # 8226; Then on the "Path" line, add the python installation path (my D:\Python32), so after that, add the path. ps: Remember, the path goes straight to ";" Separated!

The & # 8226; After setting successfully, enter the command "python" from the cmd command line to display.

Python environment variable

Here are a few important environment variables that apply to Python:

Variable name description

PYTHONPATH PYTHONPATH is the Python search path. By default, our import modules will be found in PYTHONPATH.

When PYTHONSTARTUP Python is started, look for the PYTHONSTARTUP environment variable and then execute the code in the file specified by this variable.

PYTHONCASEOK's inclusion of the PYTHONCASEOK environment variable makes python case-insensitive when importing modules.

PYTHONHOME another module search path. It is usually embedded in the PYTHONSTARTUP or PYTHONPATH directories, making it easier to switch between the two module libraries.

Run Python

There are three ways to run Python:

1. Interactive interpreter:

You can enter python from the command line window and start writing Python code in the interactive interpreter.

You can do python coding on Unix, DOS, or any other system that provides the command line or shell.


$ python # Unix/Linux

or


C:>python # Windows/DOS

The following are the Python command line parameters:

Option to describe

-ES96en displays debugging information while parsing

-ES99en generate optimization code (.pyo file)

-S startup does not introduce a location to find the Python path

-V prints the Python version number

-X since 1.6 based exceptions (for strings only) are out of date.

-ES114en cmd executes the Python script and runs the result as an cmd string.

file executes the python script on the given python file.

2. Command line scripts

In your application, you can execute the Python script from the command line by introducing an interpreter, as follows:


$ python script.py # Unix/Linux

or


C:>python script.py # Windows/DOS

Note: When executing a script, check to see if the script has executable permissions.


Related articles: