How do you add directories whose absolute path cannot be guaranteed. For eg, in the directory structure below, I would like to add the "personal", "personal/util", "personal/net" and "personal/lib" directory to sys.path. The "Python" directory could be sitting anywhere in the file system. I added sitecustome.py to "Lib/site-packages", however, I am unable to get the relative path to "personal" from there. Any ideas? Thanks for your time.

Python/
python.exe
pythonw.exe
Lib/
persona/
util/
date.py
time.py
net/
url.py
lib/
xml.py


P.S.: I understand that by putting "personal" under "site-packages" I could resolve the issue, however, I want to keep "personal" outside of "site-packages"

Generally, /python/site-python is used for individual packages. You may have to create the directory, but then could place your other directories under this one, and assuming the system knows where /python is, you could then add the path /python/site-python to $PYTHONPATH or just append your other directories to sys.path.

Generally, /python/site-python is used for individual packages. You may have to create the directory, but then could place your other directories under this one, and assuming the system knows where /python is, you could then add the path /python/site-python to $PYTHONPATH or just append your other directories to sys.path.

I wanted to know if there's a way to put the "personal" directory in sys.path while keeping it in the current location and not using absolute paths.

This article has been dead for over six months. Start a new discussion instead.