Can a Jupyter notebook load `python_library` into ...
# general
f
Can a Jupyter notebook load
python_library
into a notebook? I am able to load
pex_binary
(and other binary targets are documented to be supported). However, what about loading plain sources? My ultimate goal is to be able to write
from projectA.module import function
in Jupyter (because
projectA
is on the
sys.path
).
I have a hack:
Copy code
export PYTHONPATH=$(source .env; echo $PYTHONPATH); jupyter lab
where the
.env
file is
Copy code
PYTHONPATH="./projectA:./projectB:./projectC:$PYTHONPATH"
The
.env
file is handy for VSCode as it loads the directories by picking the file up automatically. Is modifying the
PYTHONPATH
before starting
jupyter lab
my only option or can I ask Pants nicely to load
python_sources
?
e
This is likely out of date, but you might try / improve: https://github.com/pantsbuild/pants-jupyter-plugin
f
@enough-analyst-54434 do you mean it’s not currently possible, but there is a chance that it will be possible if one extends the plugin? 🙂
e
I mean I'm just not sure. We had a spate of renaming (python_library -> python_sources) and I'm unsure how this or other refractors may have affected that project.
So maybe just give it a try.
f
sure, sure! Thanks @enough-analyst-54434
e
It looks like it works with Pants 2.8.0 but I forgot the plugin only works for pex_binary targets; not python_library / python_sources.
f
great that it works with a newer versions of Pants! Yes, that’s the problem that it only works against
pex_binary
; there is a need to be able to work with the monorepo without packaging everything. Jupyter notebooks work great OOTB in VScode thanks to the
.env
file I mentioned earlier and in PyCharm thanks to the directories marked as sources. You can just run
from projectA import foo
with any of the the monorepo directories, so it’s alright. So I wouldn’t worry too much about Pants plugin support for
python_library
— it’s essentially unnecessary given how easy it’s to change the
PYTHONPATH
before starting the
jupyter lab