Python - Module Search Path (PYTHONPATH and sys.path)

Card Puncher Data Processing

About

The path is where Python searches the modules to Import.

The current path is automatically included.

Configuration

On Windows add the script dir:

C:\Users\gerard\AppData\Roaming\Python\Python37\Scripts

What is my path

>>> import sys
>>> from pprint import pprint as pp
>>> pp(sys.path)
['',
 'C:\\Python33\\python33.zip',
 'C:\\Python33\\DLLs',
 'C:\\Python33\\lib',
 'C:\\Python33',
 'C:\\Python33\\lib\\site-packages']

PYTHONPATH

PYTHONPATH is an environment variable, that governs the sequence of directories in which Python searches for module..

sys.path

A list of strings that specifies the search path for modules. Initialized from the environment variable PYTHONPATH, plus an installation-dependent default.

As initialized upon program startup, the first item of this list, path[0], is the directory containing the script that was used to invoke the Python interpreter. If the script directory is not available (e.g. if the interpreter is invoked interactively or if the script is read from standard input), path[0] is the empty string, which directs Python to search modules in the current directory first. Notice that the script directory is inserted before the entries inserted as a result of PYTHONPATH.

A program is free to modify this list for its own purposes.

Modification

import sys
sys.path.append('/ufs/guido/lib/python')

Documentation / Reference





Discover More
Card Puncher Data Processing
Language - (Import|Include|Require)

import basically makes names (generally of function) available to the current script. To load modules, language uses different expression: imports includes. require (Node) The import functionality...
Card Puncher Data Processing
Python - Egg distribution (bdist_egg)

Python Eggs are a python binary distribution format. wheelDoc A “Python egg” is a logical structure embodying the release of a specific version...
Card Puncher Data Processing
Python - Installation and configuration

Installation and configuration of a python environment. Download it and install it Example: Linux: Configuration: Path Third library installation: You can also install...
Python Test Idea
Python - Test

in Python From the standard library: Example: doctest describe test that look like interactive Python sessions with: the command the expectations...
Card Puncher Data Processing
Python - virtualenv (Python Environment)

Python Virtual Environments allow Python packages to be installed in an isolated location for a particular project, rather than being installed globally. By default (without virtual environment), all...
Card Puncher Data Processing
Python Package - Import

import functionality in Python In order to use the names (generally, variable and function definitions) defined in a module, you must either: import the module itself or import the specific definitions,...
Card Puncher Data Processing
Python Package - init .py

A regular package is typically implemented as a directory containing an __init__.py file. The __init__.py file is tells Python that you can use the folder to import a module. (The default behavior is...



Share this page:
Follow us:
Task Runner