0

Lets say I have two git repos, A and B, depending on each other, both of which are under constant change, so it makes no sense to make them into an installable python package.

So far I solved the imports by adding the corresponding absolute paths of the other repo to sys.path.

import sys
sys.path.append("/home/path/to/B")
from package_B import function_B

But this gets rather cumbersome as for every different machine I checkout the code from, I need to adapt this path. Furthermore it messes up my commit diffs.

What is the correct way to handle these imports?

besterma
  • 46
  • 5

1 Answers1

0

This can be done using the PYTHONPATH environment variable. It augments the default search path for module imports, within python it shows up prepended to sys.path.

See here for a more extensive explanation on how to set PYTHONPATH properly.

So on every machine you checkout your repositories, you only need to adapt your PYTHONPATH once, no need for any sys.path.append.

besterma
  • 46
  • 5