void-linux / void-packages

The Void source packages collection
https://voidlinux.org
Other
2.59k stars 2.16k forks source link

venv installed packages stopped working with jupyter lab #49402

Closed Eloitor closed 8 months ago

Eloitor commented 8 months ago

Is this a new report?

Yes

System Info

Void 6.6.22_1 x86_64 GenuineIntel uptodate hold rFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Package(s) Affected

python3-3.12.2_2, jupyterlab-4.0.12_1

Does a report exist for this bug with the project's home (upstream) and/or another distro?

https://github.com/marimo-team/marimo/issues/968

Expected behaviour

I install a package in a python venv following the instuctions from and after activating it I can use it in jupyter lab. https://github.com/void-linux/void-packages/issues/47135#issuecomment-1826828577

This worked for me before but no longer works??? I don't know what happened...

Actual behaviour

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 1
----> 1 from cool_lib import a

ModuleNotFoundError: No module named 'cool_lib'

Steps to reproduce

  1. Install jupyterlab

  2. Run:

    python -m venv --system-site-packages ~/venv
    git clone https://github.com/gdamjan/hello-world-python-package.git
    cd hello-world-python-package
    ~/venv/bin/pip install -e .
    cd ..
    . ~/venv/bin/activate
    jupyter lab
  3. In jupyter lab

from cool_lib import a
classabbyamp commented 8 months ago

~/venv/bin/python -m ipykernel install --name my_cool_venv and it will show up as a kernel

Eloitor commented 8 months ago

Thanks!! This works with jupyter lab very cool trick to be able to use kernels with custom environments!

However this trick does not work with marimo as it does not use ipython. #48818

This worked before, and I'm very surprised that it doesn't work now....

Eloitor commented 8 months ago

mmm... runing python -m marimo edit test.py works. But before I only needed marimo edit test.py

ahesford commented 8 months ago

This is expected behavior. When packages are built with xbps-src, the shebang in Python scripts is deliberately overwritten to use /usr/bin/python3 instead of whatever Python interpreter might be in your path. Hence, running jupyter will ignore the virtual environment. We do this to ensure that Void-packaged Python scripts behave in a predictable manner.

If you want to override the shebang in Void-packaged scripts, you'll have to explicitly run the interpreter. You can write a wrapper or define an alias to make this happen.

Eloitor commented 8 months ago

This makes sense, but it is very strange too, because I was using this until yesterday when it stopped working...