Weird error in notebooks (Internal Python error in the inspect module)

I get this error when loading the dataset in the exercise. It runs fine when I run it on my computer.

   ERROR:root:Internal Python error in the inspect module.
    Below is the traceback from this internal error.

    ERROR:root:Internal Python error in the inspect module.
    Below is the traceback from this internal error.

    ERROR:root:Internal Python error in the inspect module.
    Below is the traceback from this internal error.

    ERROR! Session/line number was not unique in database. History logging moved to new session 33
    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/pkgutil.py", line 415, in get_importer
        importer = sys.path_importer_cache[path_item]
    KeyError: ''

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3437, in run_code
        exec(code_obj, self.user_global_ns, self.user_ns)
      File "<ipython-input-1-a9a9d24a9a56>", line 1, in <module>
        from sklearn.datasets import make_regression
      File "/opt/conda/lib/python3.8/site-packages/sklearn/__init__.py", line 82, in <module>
        from .base import clone
      File "/opt/conda/lib/python3.8/site-packages/sklearn/base.py", line 17, in <module>
        from .utils import _IS_32BIT
      File "/opt/conda/lib/python3.8/site-packages/sklearn/utils/__init__.py", line 23, in <module>
        from .class_weight import compute_class_weight, compute_sample_weight
      File "/opt/conda/lib/python3.8/site-packages/sklearn/utils/class_weight.py", line 7, in <module>
        from .validation import _deprecate_positional_args
      File "/opt/conda/lib/python3.8/site-packages/sklearn/utils/validation.py", line 26, in <module>
        from .fixes import _object_dtype_isnan, parse_version
      File "/opt/conda/lib/python3.8/site-packages/sklearn/utils/fixes.py", line 28, in <module>
        from pkg_resources import parse_version  # type: ignore
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3268, in <module>
        def _initialize_master_working_set():
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3251, in _call_aside
        f(*args, **kwargs)
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3280, in _initialize_master_working_set
        working_set = WorkingSet._build_master()
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 573, in _build_master
        ws = cls()
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 566, in __init__
        self.add_entry(entry)
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 622, in add_entry
        for dist in find_distributions(entry, True):
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 1979, in find_distributions
        importer = get_importer(path_item)
      File "/opt/conda/lib/python3.8/pkgutil.py", line 419, in get_importer
        importer = path_hook(path_item)
      File "<frozen importlib._bootstrap_external>", line 1522, in path_hook_for_FileFinder
      File "<frozen importlib._bootstrap_external>", line 107, in _path_isdir
    FileNotFoundError: [Errno 2] No such file or directory

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2061, in showtraceback
        stb = value._render_traceback_()
    AttributeError: 'FileNotFoundError' object has no attribute '_render_traceback_'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1101, in get_records
        return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 248, in wrapped
        return f(*args, **kwargs)
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 281, in _fixed_getinnerframes
        records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
      File "/opt/conda/lib/python3.8/inspect.py", line 1515, in getinnerframes
        frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
      File "/opt/conda/lib/python3.8/inspect.py", line 1473, in getframeinfo
        filename = getsourcefile(frame) or getfile(frame)
      File "/opt/conda/lib/python3.8/inspect.py", line 708, in getsourcefile
        if getattr(getmodule(object, filename), '__loader__', None) is not None:
      File "/opt/conda/lib/python3.8/inspect.py", line 737, in getmodule
        file = getabsfile(object, _filename)
      File "/opt/conda/lib/python3.8/inspect.py", line 721, in getabsfile
        return os.path.normcase(os.path.abspath(_filename))
      File "/opt/conda/lib/python3.8/posixpath.py", line 379, in abspath
        cwd = os.getcwd()
    FileNotFoundError: [Errno 2] No such file or directory
    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/pkgutil.py", line 415, in get_importer
        importer = sys.path_importer_cache[path_item]
    KeyError: ''

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3437, in run_code
        exec(code_obj, self.user_global_ns, self.user_ns)
      File "<ipython-input-1-a9a9d24a9a56>", line 1, in <module>
        from sklearn.datasets import make_regression
      File "/opt/conda/lib/python3.8/site-packages/sklearn/__init__.py", line 82, in <module>
        from .base import clone
      File "/opt/conda/lib/python3.8/site-packages/sklearn/base.py", line 17, in <module>
        from .utils import _IS_32BIT
      File "/opt/conda/lib/python3.8/site-packages/sklearn/utils/__init__.py", line 23, in <module>
        from .class_weight import compute_class_weight, compute_sample_weight
      File "/opt/conda/lib/python3.8/site-packages/sklearn/utils/class_weight.py", line 7, in <module>
        from .validation import _deprecate_positional_args
      File "/opt/conda/lib/python3.8/site-packages/sklearn/utils/validation.py", line 26, in <module>
        from .fixes import _object_dtype_isnan, parse_version
      File "/opt/conda/lib/python3.8/site-packages/sklearn/utils/fixes.py", line 28, in <module>
        from pkg_resources import parse_version  # type: ignore
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3268, in <module>
        def _initialize_master_working_set():
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3251, in _call_aside
        f(*args, **kwargs)
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3280, in _initialize_master_working_set
        working_set = WorkingSet._build_master()
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 573, in _build_master
        ws = cls()
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 566, in __init__
        self.add_entry(entry)
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 622, in add_entry
        for dist in find_distributions(entry, True):
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 1979, in find_distributions
        importer = get_importer(path_item)
      File "/opt/conda/lib/python3.8/pkgutil.py", line 419, in get_importer
        importer = path_hook(path_item)
      File "<frozen importlib._bootstrap_external>", line 1522, in path_hook_for_FileFinder
      File "<frozen importlib._bootstrap_external>", line 107, in _path_isdir
    FileNotFoundError: [Errno 2] No such file or directory

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2061, in showtraceback
        stb = value._render_traceback_()
    AttributeError: 'FileNotFoundError' object has no attribute '_render_traceback_'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3357, in run_ast_nodes
        if (await self.run_code(code, result,  async_=asy)):
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3454, in run_code
        self.showtraceback(running_compiled_code=True)
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2063, in showtraceback
        stb = self.InteractiveTB.structured_traceback(etype,
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1367, in structured_traceback
        return FormattedTB.structured_traceback(
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1267, in structured_traceback
        return VerboseTB.structured_traceback(
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1124, in structured_traceback
        formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1082, in format_exception_as_a_whole
        last_unique, recursion_repeat = find_recursion(orig_etype, evalue, records)
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 382, in find_recursion
        return len(records), 0
    TypeError: object of type 'NoneType' has no len()

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2061, in showtraceback
        stb = value._render_traceback_()
    AttributeError: 'TypeError' object has no attribute '_render_traceback_'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1101, in get_records
        return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 248, in wrapped
        return f(*args, **kwargs)
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 281, in _fixed_getinnerframes
        records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
      File "/opt/conda/lib/python3.8/inspect.py", line 1515, in getinnerframes
        frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
      File "/opt/conda/lib/python3.8/inspect.py", line 1473, in getframeinfo
        filename = getsourcefile(frame) or getfile(frame)
      File "/opt/conda/lib/python3.8/inspect.py", line 708, in getsourcefile
        if getattr(getmodule(object, filename), '__loader__', None) is not None:
      File "/opt/conda/lib/python3.8/inspect.py", line 737, in getmodule
        file = getabsfile(object, _filename)
      File "/opt/conda/lib/python3.8/inspect.py", line 721, in getabsfile
        return os.path.normcase(os.path.abspath(_filename))
      File "/opt/conda/lib/python3.8/posixpath.py", line 379, in abspath
        cwd = os.getcwd()
    FileNotFoundError: [Errno 2] No such file or directory
    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/pkgutil.py", line 415, in get_importer
        importer = sys.path_importer_cache[path_item]
    KeyError: ''

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3437, in run_code
        exec(code_obj, self.user_global_ns, self.user_ns)
      File "<ipython-input-1-a9a9d24a9a56>", line 1, in <module>
        from sklearn.datasets import make_regression
      File "/opt/conda/lib/python3.8/site-packages/sklearn/__init__.py", line 82, in <module>
        from .base import clone
      File "/opt/conda/lib/python3.8/site-packages/sklearn/base.py", line 17, in <module>
        from .utils import _IS_32BIT
      File "/opt/conda/lib/python3.8/site-packages/sklearn/utils/__init__.py", line 23, in <module>
        from .class_weight import compute_class_weight, compute_sample_weight
      File "/opt/conda/lib/python3.8/site-packages/sklearn/utils/class_weight.py", line 7, in <module>
        from .validation import _deprecate_positional_args
      File "/opt/conda/lib/python3.8/site-packages/sklearn/utils/validation.py", line 26, in <module>
        from .fixes import _object_dtype_isnan, parse_version
      File "/opt/conda/lib/python3.8/site-packages/sklearn/utils/fixes.py", line 28, in <module>
        from pkg_resources import parse_version  # type: ignore
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3268, in <module>
        def _initialize_master_working_set():
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3251, in _call_aside
        f(*args, **kwargs)
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3280, in _initialize_master_working_set
        working_set = WorkingSet._build_master()
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 573, in _build_master
        ws = cls()
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 566, in __init__
        self.add_entry(entry)
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 622, in add_entry
        for dist in find_distributions(entry, True):
      File "/opt/conda/lib/python3.8/site-packages/pkg_resources/__init__.py", line 1979, in find_distributions
        importer = get_importer(path_item)
      File "/opt/conda/lib/python3.8/pkgutil.py", line 419, in get_importer
        importer = path_hook(path_item)
      File "<frozen importlib._bootstrap_external>", line 1522, in path_hook_for_FileFinder
      File "<frozen importlib._bootstrap_external>", line 107, in _path_isdir
    FileNotFoundError: [Errno 2] No such file or directory

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2061, in showtraceback
        stb = value._render_traceback_()
    AttributeError: 'FileNotFoundError' object has no attribute '_render_traceback_'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3357, in run_ast_nodes
        if (await self.run_code(code, result,  async_=asy)):
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3454, in run_code
        self.showtraceback(running_compiled_code=True)
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2063, in showtraceback
        stb = self.InteractiveTB.structured_traceback(etype,
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1367, in structured_traceback
        return FormattedTB.structured_traceback(
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1267, in structured_traceback
        return VerboseTB.structured_traceback(
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1124, in structured_traceback
        formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1082, in format_exception_as_a_whole
        last_unique, recursion_repeat = find_recursion(orig_etype, evalue, records)
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 382, in find_recursion
        return len(records), 0
    TypeError: object of type 'NoneType' has no len()

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2061, in showtraceback
        stb = value._render_traceback_()
    AttributeError: 'TypeError' object has no attribute '_render_traceback_'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2940, in _run_cell
        return runner(coro)
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/async_helpers.py", line 68, in _pseudo_sync_runner
        coro.send(None)
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3165, in run_cell_async
        has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3376, in run_ast_nodes
        self.showtraceback()
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2063, in showtraceback
        stb = self.InteractiveTB.structured_traceback(etype,
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1367, in structured_traceback
        return FormattedTB.structured_traceback(
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1267, in structured_traceback
        return VerboseTB.structured_traceback(
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1142, in structured_traceback
        formatted_exceptions += self.format_exception_as_a_whole(etype, evalue, etb, lines_of_context,
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1082, in format_exception_as_a_whole
        last_unique, recursion_repeat = find_recursion(orig_etype, evalue, records)
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 382, in find_recursion
        return len(records), 0
    TypeError: object of type 'NoneType' has no len()

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2061, in showtraceback
        stb = value._render_traceback_()
    AttributeError: 'TypeError' object has no attribute '_render_traceback_'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 1101, in get_records
        return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 248, in wrapped
        return f(*args, **kwargs)
      File "/opt/conda/lib/python3.8/site-packages/IPython/core/ultratb.py", line 281, in _fixed_getinnerframes
        records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
      File "/opt/conda/lib/python3.8/inspect.py", line 1515, in getinnerframes
        frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
      File "/opt/conda/lib/python3.8/inspect.py", line 1473, in getframeinfo
        filename = getsourcefile(frame) or getfile(frame)
      File "/opt/conda/lib/python3.8/inspect.py", line 708, in getsourcefile
        if getattr(getmodule(object, filename), '__loader__', None) is not None:
      File "/opt/conda/lib/python3.8/inspect.py", line 737, in getmodule
        file = getabsfile(object, _filename)
      File "/opt/conda/lib/python3.8/inspect.py", line 721, in getabsfile
        return os.path.normcase(os.path.abspath(_filename))
      File "/opt/conda/lib/python3.8/posixpath.py", line 379, in abspath
        cwd = os.getcwd()
    FileNotFoundError: [Errno 2] No such file or directory

I encountered this error at least once … cc @brospars for visibility.

If I remember correctly, it went away by restarting the kernel a few times, can you try this ?

Yes, that did the trick…
But I probably won’t be the only running into the problem.

Agreed the thing is that it is seems not that easy to guess what is happening from the stacktrace … worth googling a bit.

It is very likely not linked to this particular exercise but a general JupyterHub thing. I am going to create a jupyterhub tag for this kind of things.