Home  >  Article  >  Backend Development  >  How to set up a python environment

How to set up a python environment

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-13 11:08:262567browse

First download the python version suitable for the system. Programs and executable files can be in many directories, and these paths are most likely not in the search path provided by the operating system for executable files. Path (path) is stored in an environment variable, which is a named string maintained by the operating system. These variables contain information about available command line interpreters and other programs.

The path variable in Unix or Windows is PATH (UNIX is case-sensitive, Windows is not case-sensitive).

In Mac OS, the installation path of python is changed during the installation process. If you need to reference Python from another directory, you must add the Python directory to the path.

How to set up a python environment

Set environment variables in Unix/Linux

In csh shell: Enter

setenv PATH "$PATH:/usr/local/bin/python"

Press "Enter". In bash shell (Linux): Type

export PATH="$PATH:/usr/local/bin/python"

and press "Enter". In sh or ksh shell: type

PATH="$PATH:/usr/local/bin/python"

and press "Enter".

Note: /usr/local/bin/python is the installation directory of Python.

Related recommendations: "python video tutorial"

Set environment variables in Windows

In Add the Python directory to the environment variable:

In the command prompt box (cmd): enter

path=%path%;C:\Python

and press "Enter".

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

You can also set it in the following ways:

Right-click "Computer", then click "Properties" and then click "Advanced System Settings", select "Path" under the "System Variables" window, and double-click That’s 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 to display the relevant information.

How to set up a python environment

Python environment variables

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

variable name Description

## Pythonpath PythonPath is the Python search path. By default, our Import module will look for it 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 to join the environment variable of PythoncaseOk, which will make Python not distinguish between latter 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.

The above is the detailed content of How to set up a python environment. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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