-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent importing of local modules when starting a new Notebook #12914
Comments
This is mainly an |
I think that we should try to address it in JupyterLab, as this problem affects many novice users (based on frequency of this question on StackOverflow)discouraging them from using JupyterLab. While we do not explicitly handle the Other editors also try to make the experience better for novice users (although there are conflicting opinions on how to handle it best), for example Spyder: spyder-ide/spyder#17066. |
Thanks @krassowski. What I meant here was that, as it stands, JupyterLab can't do anything - it doesn't intrinsically care about what kernel the user is running. If we want to special-case something for ipykernel, then we might be able to first modify ipykernel to accept an option, and then JupyterLab to provide it to the kernel environment. |
There is another one - when you open a debugger with ipykernel having a file named File "/3.9.5/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/3.9.5/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/3.9.5/envs/ipython/lib/python3.9/site-packages/ipykernel_launcher.py", line 15, in <module>
from ipykernel import kernelapp as app
File "/3.9.5/envs/ipython/lib/python3.9/site-packages/ipykernel/kernelapp.py", line 51, in <module>
from .ipkernel import IPythonKernel
File "/3.9.5/envs/ipython/lib/python3.9/site-packages/ipykernel/ipkernel.py", line 19, in <module>
from .debugger import Debugger, _is_debugpy_available
File "/3.9.5/envs/ipython/lib/python3.9/site-packages/ipykernel/debugger.py", line 22, in <module>
from debugpy.server import api # noqa
File "/3.9.5/envs/ipython/lib/python3.9/site-packages/debugpy/server/__init__.py", line 7, in <module>
import debugpy._vendored.force_pydevd # noqa
File "/3.9.5/envs/ipython/lib/python3.9/site-packages/debugpy/_vendored/force_pydevd.py", line 28, in <module>
pydevd_constants = import_module('_pydevd_bundle.pydevd_constants')
File "/3.9.5/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/3.9.5/envs/ipython/lib/python3.9/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_constants.py", line 379, in <module>
from _pydev_bundle._pydev_saved_modules import thread, threading
File "/3.9.5/envs/ipython/lib/python3.9/site-packages/debugpy/_vendored/pydevd/_pydev_bundle/_pydev_saved_modules.py", line 91, in <module>
import code as _code; verify_shadowed.check(_code, ['compile_command', 'InteractiveInterpreter'])
File "/3.9.5/envs/ipython/lib/python3.9/site-packages/debugpy/_vendored/pydevd/_pydev_bundle/_pydev_saved_modules.py", line 75, in check
raise DebuggerInitializationError(msg)
_pydev_bundle._pydev_saved_modules.DebuggerInitializationError: It was not possible to initialize the debugger due to a module name conflict.
i.e.: the module "code" could not be imported because it is shadowed by:
/path/to/root/code.py
Please rename this file/folder so that the original module from the standard library can be imported. This is actually hard to recover from (cf #13069, other than removing the |
I don't believe this is in JupyterLab, it is either in Jupyter Client, or in ipykernel. |
Given a number of reports I do think we need to do something about
This is particularly erogenous for new users, and exacerbates with time as more dependencies get added to the kernels and any server-side code which may get broken in that way (but on startup rather than on kernel launch). |
Problem
A new Notebook starts in the current working directory. This means a file named
logging.py
in my working directory shadows the modulelogging
of the standard library. Accordingly, I get this error message on the console from which I started the server:The Notebook cannot connect to a kernel. After deleting
logging.py
, creating a new Notebook works again without problem. So the obvious solutions is not name own modules with names of module of the standard library, which is alway a good idea. There are few problems with this solutions:Proposed Solution
These maybe solutions:
sys.path
so that the current directory is not in the search path. Setsys.path
back to its original state after all relevant imports.mod
do aassert Path(mod.__file__).parent != Path().resolve()
. The error message needs to be shown in the UI.Additional context
Tested with JupyterLab version 3.3.4.
The text was updated successfully, but these errors were encountered: