Different Environment variable

In this article, we will explore some of the most prominent environment variables in Python.

It is used to set the path for the user-defined modules so that it can be directly imported into a Python program. It is also responsible for handling the default search path for Python Modules. The PYTHONPATH variable holds a string with the name of various directories that needs to be added to the sys.path directory list by Python. The primary use of this variable is to allow users to import modules that are not made installable yet. 

PYTHONHOME

This variable is used to set the default location of the standard Python libraries. By Default, Python searches for its libraries in prefix/lib/pythonversion and exec_prefix/lib/pythonversion. Here the prefix and exec_prefix are installation-dependent directories, and both of them default to /usr/local.

PYTHONSTARTUP

Whenever the python interpreted is first initialized Python looks for a readable file with the name .pythonrc.py in Unix and executes the commands inside it. The path to the same file is stored in the PYTHONSTARTUP variable. These files are responsible for setting up the PYTHONPATH.

PYTHONINSPECT

If the PYTHONINSPECT variable is an empty string, it compels python to enter into an interactive python-mode and ignore the PYTHONSTARTUP files.  It can also make changes to the Python code and force it to enter the inspect mode on program termination. It is equivalent to using the -i command-line option.

PYTHONCASEOK

This environment variable is used to ignore all import statements while calling the Python interpreter. In a Windows machine, it is used to find the first case-insensitive match in an import statement.

PYTHONVERBOSE

If this variable is set to an empty string, it prints a message every time a module is initialized showing the location of the file or the module from where it has been loaded. It also generates information on module cleanup at the termination of the python program.

The above variables are the primary environment variables that are frequently used.

Environment Variables in Python

In Python, its behavior is highly influenced by the setup of the environment variables.  There is a fixed number of environment variables that Python recognizes and these generally are processed before the command line switches. Whenever a conflict arises between the environmental variable and the command line switches, the environment variable gets overridden.

Similar Reads

Different Environment variable

In this article, we will explore some of the most prominent environment variables in Python....

Ways of executing code in Python

There are 3 standard ways of using Python, namely:...