When you run the test1.py script, it works because Python will add the script's directory automatically to sys.path (which contains the directories to be searched during imports):
[...] As initialized upon program startup, the first item of this list, path[0], is the directory containing the script that was used to invoke the Python interpreter. [...]
So when import foobar is encountered, it will successfully search the directory project/pack1 since that is the directory which also contains the test1.py script.
However, when you run baz.py, since it resides in another directory, project/pack1 is never added to sys.path and thus foobar.py cannot be found.
You can fix this by using the following import statement in test1.py:
from . import foobar
This tells Python that the foobar module is located inside the same package as the importing module (i.e. test1 in this case). Now running python baz.py should work.
However, when you try to run python pack1/test1.py now, there should be an error similar to:
[...]
from . import foobar
ImportError: attempted relative import with no known parent package
This is because when you run python pack1/test1.py directly, is has no information about the package that contains the test1 module. You can fix this by invoking the script with the -m switch:
/path/to/project$ python -m pack1.test1
/path/to/project$ python baz.py
Both of the above should work now.