holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.6k stars 499 forks source link

PYTHONPATH first element not used in jupyter preview #6962

Closed jordansamuels closed 1 month ago

jordansamuels commented 1 month ago

This bug appears related to the change in #4489 . That change uses sys.path[1:] , but this means that the first element of the path is omitted. This causes import issues in panel preview when importing a file from the first element of the PYTHONPATH. Moreover, if I locally change to sys.path instead of sys.path[1:] in panel/io/jupyter_server_extension.py then it fixes the issue.

ALL software version info

Tested on OSX and Linux. Full software versions in repro here.

Description of expected behavior and the observed behavior

Full repro instructions at https://github.com/jordansamuels/panel-jupyter-path-bug-repro.
Expected: panel preview works in jupyter lab. Observed: import exception.

Complete, minimal, self-contained example code that reproduces the issue

Full repro at https://github.com/jordansamuels/panel-jupyter-path-bug-repro.

Stack traceback and/or browser JavaScript console output

(none relevant that I could find)

Screenshots or screencasts of the bug in action

image
MarcSkovMadsen commented 1 month ago

Hi @jordansamuels

Thanks for the well described bug report. You could try to make the PR by just changing sys.path = [os.getcwd()] + sys.path[1:] to sys.path = [os.getcwd()] + sys.path.

As there is no test or documentation of the change in 4489, then Philipp would be the only one knowing why it was [1:] anyways and he would be able to quickly pick up and adjust your PR if needed.

jordansamuels commented 1 month ago

[...] You could try to make the PR by just changing sys.path = [os.getcwd()] + sys.path[1:] to sys.path = [os.getcwd()] + sys.path.

Thanks! I made PR #7059 for this. This is my first PR for this repo, so please let me know if I can adjust anything.