Python path: Reusing Python module

path, python, ubuntu

Solution

You can add a `PYTHONPATH` environment variable to your `.bashrc` file. eg.

export PYTHONPATH=/projects/my_py_lib

Problem

I have written a small DB access module that is extensively reused in many programs. My code is stored in a single directory tree `/projects` for backup and versioning reasons, and so the module should be placed within this directory tree, say at `/projects/my_py_lib/dbconn.py`. I want to easily configure Python to automatically search for modules at the `/projects/my_py_lib` directory structure (of course, `__init__.py` should be placed within any subdirectory). What's the best way to do this under Ubuntu? Thanks, Adam

Original source