Suppose you have sharedUtils/utils_foo
and sharedUtils/utils_bar
.
You could edit your PYTHONPATH to include sharedUtils
, then import them in project1
and project2
using
import utils_foo
import utils_bar
etc.
In linux you could do that be editing ~/.profile with something like this:
PYTHONPATH=/path/to/sharedUtils:/other/paths
export PYTHONPATH
Using the PYTHONPATH environment variable affects the directories that python searches when looking for modules. Since every user can set his own PYTHONPATH, this solution is good for personal projects.
If you want all users on the machine to be able to import modules in sharedUtils
, then
you can achieve this by using a .pth
file. Exactly where you put the .pth
file may depend on your python distribution. See
http://bob.pythonmac.org/archives/2005/02/06/using-pth-files-for-python-development/