Is it possible to use environment variables to specify a library path in python .pth files and if yes, how so?
Background: My python project (lives in /path/to/my/project) runs in a virtualenv, but needs to use an external (but local) package. Using virtualenv with --sytem-site-packages is not an option, therefore I added the path to the external package via a .pth file as suggested by this answer. The .pth lies in /path/to/my/project/lib/python2.7/site-packages and contains only the following line:
/path/to/external_dir/etc/python
This works as expected and allows me to import the external library.
In order to use my project on a different computer, I want to use an environment variable in the path instead of an absolute path. I can be sure that the environment variable EXTERNAL_DIR is set as follows before python is started:
export EXTERNAL_DIR="/path/to/external_dir"
But if /path/to/external_dir in the .pth file is replaced by ${EXTERNAL_DIR} I get an import error. The content of the .pth file then looks like this:
${EXTERNAL_DIR}/etc/python
Is this simply not the correct way to use the environment variable or is it not possible to use them in .pth files at all?
I'm using Debian, bash and python 2.7.