jupyter / nbgrader

A system for assigning and grading notebooks
https://nbgrader.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.3k stars 317 forks source link

student python packages can interfere with nbgrader #1842

Closed clhedrick closed 4 months ago

clhedrick commented 1 year ago

Operating system

Ubuntu 22.03

nbgrader --version

Python version 3.11.3 (main, Apr 19 2023, 23:54:32) [GCC 11.2.0] nbgrader version 0.8.4

jupyterhub --version (if used with JupyterHub)

3.1.1

jupyterlab--version

3.6.5

Expected behavior

Several students installed versions of sqlalchemy for use in their notebooks. This causes nbgrader to be unable to find their assignments. My interpretation of the error is that nbgrader tried to use their version of sqlalchemy, and it was missing an extension needed by nbgrader.

I would expect that the jupyter framework and nbgrader would use python paths that don't include anything in the user's home directory. I tried to modify code to do this, but was unable to find a place that fixed the problem.

lahwaacz commented 1 year ago

What is the actual error you observed?

clhedrick commented 1 year ago

I'm giving you the whole error below. But note the last line, which is the key. It's using sqlalchemy from the user's home directory. When I remove /home/XXX/.local/lib, it starts working.

I can force a failure by defining any module used by jupyterhub with a bogus definition in /home/XXX/.local

I can fix it by setting env['PYTHONNOUSERSITE'] = "1" in LocalProcessSpawner getenv

However that's less than optimal, because that environment variable is then set in all kernels, which we don't want. We want users to be able to use their own modules in code they write. For the moment I'm adding env['PYTHONNOUSERSITE'] = "" to all the kernel.json files.

Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: [W 2023-10-22 01:29:58.809 SingleUserLabApp manager:327] nbgrader.server_extensions.assignment_list | err\ or adding extension (enabled: True): The module 'nbgrader.server_extensions.assignment_list' could not be found (cannot import name 'DeclarativeBase' from\ 'sqlalchemy.orm' (/home/as3900/.local/lib/python3.11/site-packages/sqlalchemy/orm/init.py)). Are you sure the extension is installed? Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: Traceback (most recent call last): Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "/usr/lib/anaconda3/lib/python3.11/site-packages/jupyter_server/extension/manager.py", line 17\ 5, in _validate_name Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: self._module, self._metadata = get_metadata(name) Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: ^^^^^^^^^^^^^^^^^^ Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "/usr/lib/anaconda3/lib/python3.11/site-packages/jupyter_server/extension/utils.py", line 60, \ in get_metadata Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: module = importlib.import_module(package_name) Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "/usr/lib/anaconda3/lib/python3.11/importlib/init.py", line 126, in import_module Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: return _bootstrap._gcd_import(name[level:], package, level) Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "", line 1206, in _gcd_import Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "", line 1178, in _find_and_load Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "", line 1128, in _find_and_load_unlocked Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "", line 241, in _call_with_frames_removed Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "", line 1206, in _gcd_import Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "", line 1178, in _find_and_load Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "", line 1128, in _find_and_load_unlocked Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "", line 241, in _call_with_frames_removed Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "", line 1206, in _gcd_import Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "", line 1178, in _find_and_load Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "", line 1128, in _find_and_load_unlocked Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "", line 241, in _call_with_frames_removed Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "", line 1206, in _gcd_import Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "", line 1178, in _find_and_load Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "", line 1149, in _find_and_load_unlocked Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "", line 690, in _load_unlocked Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "", line 940, in exec_module Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "", line 241, in _call_with_frames_removed Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "/usr/lib/anaconda3/lib/python3.11/site-packages/nbgrader/init.py", line 11, in Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: from .server_extensions.assignment_list import load_jupyter_server_extension as load_assignments Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "/usr/lib/anaconda3/lib/python3.11/site-packages/nbgrader/server_extensions/assignment_list/\ init.py", line 1, in Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: from .handlers import load_jupyter_server_extension Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "/usr/lib/anaconda3/lib/python3.11/site-packages/nbgrader/server_extensions/assignment_list/ha\

Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: from .handlers import load_jupyter_server_extension Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "/usr/lib/anaconda3/lib/python3.11/site-packages/nbgrader/server_extensions/assignment_list/ha\ ndlers.py", line 17, in Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: from ...exchange import ExchangeFactory, ExchangeError Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "/usr/lib/anaconda3/lib/python3.11/site-packages/nbgrader/exchange/init.py", line 5, in <m\ odule> Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: from .exchange_factory import ExchangeFactory Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "/usr/lib/anaconda3/lib/python3.11/site-packages/nbgrader/exchange/exchange_factory.py", line \ 4, in Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: from nbgrader.exchange import default, abc Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "/usr/lib/anaconda3/lib/python3.11/site-packages/nbgrader/exchange/default/init.py", line \ 7, in Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: from .collect import ExchangeCollect Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "/usr/lib/anaconda3/lib/python3.11/site-packages/nbgrader/exchange/default/collect.py", line 1\ 3, in Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: from ...api import Gradebook, MissingEntry Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: File "/usr/lib/anaconda3/lib/python3.11/site-packages/nbgrader/api.py", line 11, in Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: from sqlalchemy.orm import (sessionmaker, scoped_session, relationship, Oct 22 01:29:58 data7.cs.rutgers.edu jupyterhub: ImportError: cannot import name 'DeclarativeBase' from 'sqlalchemy.orm' (/home/XXXx/.local/lib/pyth\ on3.11/site-packages/sqlalchemy/orm/init.py) O


From: Jakub Klinkovský @.> Sent: Wednesday, October 25, 2023 3:39 PM To: jupyter/nbgrader @.> Cc: Charles Hedrick @.>; Author @.> Subject: Re: [jupyter/nbgrader] student python packages can interfere with nbgrader (Issue #1842)

What is the actual error you observed?

— Reply to this email directly, view it on GitHubhttps://github.com/jupyter/nbgrader/issues/1842#issuecomment-1779935242, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAORUCATXIVRX4QMWI7ACNLYBFTGBAVCNFSM6AAAAAA6PYCQMSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZZHEZTKMRUGI. You are receiving this because you authored the thread.Message ID: @.***>

shreve commented 4 months ago

This ImportError based on a regression that shipped in 0.8.4, but is now fixed in 0.8.5: https://github.com/jupyter/nbgrader/commit/7079e6af82abb4baeda4fcca4cbcab238cfe32d1

brichet commented 4 months ago

Seems to be solved, thanks @shreve for the update.

Feel free to reopen it if the issue is still relevant.