Home  >  Article  >  Backend Development  >  What does python pythonpath mean?

What does python pythonpath mean?

little bottle
little bottleOriginal
2019-05-20 10:50:4715655browse

Pythonpath is an important environment variable in Python. It is used to search for paths when importing modules. By accessing Pythonpath, you can see that the first element of the path list is an empty string, which represents a relative path. the current directory under.

What does python pythonpath mean?

Pythonpath is an important environment variable in Python, used to search for paths when importing modules. This article will tell you how to access it.

Can be accessed in the following ways:

>>> import sys
>>> sys.path
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', 
'/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', 
'/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']

As you can see, the first element of the path list is an empty string, which represents the current directory under a relative path.

Since when importing a module, the interpreter will search in the order of the list until it finds the first module, so the modules imported first are modules in the same directory.

When importing modules The order of search paths can also be changed. There are two situations here:

1, changed through sys.path.append(), sys.path.insert() and other methods. This method will be interpreted when restarting When the server is installed, the original settings will become invalid.

2. Change PYTHONPATH. This setting method is permanently effective:

In this case, you can pass the path displayed in the sys.path list Add a .pth file to achieve this.

The above is the detailed content of What does python pythonpath mean?. 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