I like to keep my VTK up to date; some of my project unfortunately require older versions. So I thought of how to "activate" a particular package without having to swap
.pth files in and out to my site-packages/ directory, but rather by setting up the more accessible
PYTHONPATH environment variable. If vtk were a pure Python package, this would be all that were required, but we need the OS to find the right shared binary libraries as well, so we need to manipulate the OS
PATH as well. In a
.pth file, this can of course be done with an
import os; os.environ['PATH']='/path/to/vtk;'+os.environ['PATH']
in the
.pth file, but then the lexically later
.pth file name wins in prepending their
os.environ['PATH'].
A better way is to directly place the os stuff in the __init__.py files of the vtk packages, like so:
import re
x=os.path.realpath(__file__)
os.environ['PATH']=os.path.join(re.split('lib',x)[0],'bin')+';'+os.environ['PATH']
Admitted, it's ugly to have to edit this file, which gets generated during the build process, but hey, it works really well.