I usually do that by either having the py file in the working directory of the session, in which case you simply import it.

Alternatively something like this in python:

import sys
sys.path.insert(0, '/path/to/dir/with/myfile.py')
import myfile

you could also append to sys.path if that matters.

John

-----------------------------------
Professor John Kitchin 
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803


On Mon, Nov 23, 2020 at 10:49 AM Joost Kremers <joostkremers@fastmail.fm> wrote:
Hi all,

If I have an Org file with Python source blocks, I can run them in a session
with the `:session` header arg. That way, I can include packages installed in
`site-packages` and have them available in all code blocks. But is there a way
to import my own packages into a session? In particular, packages I haven't
installed system-wide?

What I'm trying to do is to import a Python file with a bunch of utility
functions into the ob-python session. I thought this might be possible if I'd
structure my code as a regular Python package, because that works if I want to
import my utility functions into another Python file. But it doesn't seem to
work for the ob-python session.

Is there a way to achieve this? I don't *have* to structure my utility functions
as a Python package, so if there's another way of doing this, I'd be interested
as well.

TIA

Joost


--
Joost Kremers
Life has its moments