How to import functions from other projects in Python?

Ideally both projects will be an installable python package, replete with and They could then be installed with python install or similar.

If that is not possible, don’t use execfile()! Manipulate the PYTHONPATH to add Foo so that import Project1.file1 works.

For example, from Project2/

from os import path
import sys

from Project1.file1 import something

However, the real answer is to make each a discrete installable package.

Leave a Comment