Walkthrough of setting Python environment variables in windows

Source: Internet
Author: User
Below for you to share an example of setting up Python environment variables in Windows to explain, with a good reference value, I hope to be helpful to everyone. Come and see it together.

Setting environment variables in Windows

To add a Python directory to an environment variable:

In the Command Prompt box (cmd): Enter

path=%path%; C:\Python

Press "Enter".

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

You can also set it in the following ways:

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

• Then click on "Advanced system Settings"

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

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

• After the final setup is successful, on the cmd command line, enter the command "Python" and you can have the relevant display.

Python Environment variables

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

Variable name Description

PYTHONPATH PYTHONPATH is the Python search path, and the default import module will be searched from PYTHONPATH.

Pythonstartup python starts, look for the PYTHONSTARTUP environment variable, and then execute the code in the file specified by this variable.

Pythoncaseok joins the PYTHONCASEOK environment variable, it makes Python import the module is not case-sensitive.

Pythonhome another module search path. It is typically embedded in the Pythonstartup or Pythonpath directory, making it easier to switch between two module libraries.

Run Python

There are three ways to run Python:

1. Interactive interpreter:

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

You can do python coding in unix,dos or any other system that provides a command line or shell.

$ python # Unix/linux

Or

C:>python # Windows/dos

The following are the Python command-line parameters:

Option description

-D displays debug information at parse time

-O Generate Optimization code (. pyo file)

-S does not introduce a location to find Python paths when booting

-V Output Python version number

-X is obsolete based on the built-in exception (for strings only) since version 1.6.

-C CMD executes the Python script and runs the result as a CMD string.

File executes the Python script in the given Python file.

2. Command line script

In your application, you can execute a python script on 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.