Suppose I want to edit
PYTHONPATH = /home/CURRENT_USER/
- How do I have a variable that will automatically fill in the current user?
- What about hostname?
- Aren't these environment variables?
$USER should typically be set to the current user, and
$HOSTNAME to the current hostname. If not, you can also get them from the output of
Also, the user's home directory is not necessarily in
/home/[username]. You should use the value of
Another approach is to add a call to
sitecustomize.py rather than PYTHONPATH.
However since Python 2.6 you probably don't need to do either, because
/home/$USER/.local/lib/python2.6/site-packages is automatically added to
sys.path. This is a good choice of standard place to put user-specific modules/packages; you wouldn't really want to add the home directory itself as a module path as it contains all sorts of things that aren't modules, which could confuse imports.
See PEP370 for details.