SQL suddenly not working in Jupyter after Kernal restart

I was using SQL code just fine and without issue in my Jupyter Notebook, until I restarted Kernal and Ran all - now I’m getting a ModuleNotFoundError.

I was doing this project through Anaconda.

My Code:

%load_ext sql 
%sql sqlite:///database/factbook.db

What I expected to happen:

Expected it to read the database file, just as it had done without issue an hour ago.

What actually happened:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-5-af67b720b8f0> in <module>
----> 1 get_ipython().run_line_magic('load_ext', 'sql ')
      2 get_ipython().run_line_magic('sql', 'sqlite:///database/factbook.db')

C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
   2324                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2325             with self.builtin_trap:
-> 2326                 result = fn(*args, **kwargs)
   2327             return result

<decorator-gen-65> in load_ext(self, module_str)

C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    189         if callable(arg):

C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\magics\extension.py in load_ext(self, module_str)
     31         if not module_str:
     32             raise UsageError('Missing module name.')
---> 33         res = self.shell.extension_manager.load_extension(module_str)
     35         if res == 'already loaded':

C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\extensions.py in load_extension(self, module_str)
     78             if module_str not in sys.modules:
     79                 with prepended_to_syspath(self.ipython_extension_dir):
---> 80                     mod = import_module(module_str)
     81                     if mod.__file__.startswith(self.ipython_extension_dir):
     82                         print(("Loading extensions from {dir} is deprecated. "

C:\ProgramData\Anaconda3\lib\importlib\__init__.py in import_module(name, package)
    125                 break
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap.py in _gcd_import(name, package, level)

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap.py in _find_and_load(name, import_)

C:\ProgramData\Anaconda3\lib\importlib\_bootstrap.py in _find_and_load_unlocked(name, import_)

ModuleNotFoundError: No module named 'sql '

ipython-sql is still installed, and is confirmed when I run

!conda install -yc conda-forge ipython-sql

Which outputs:

Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... done

# All requested packages already installed.

Well, I just figured it out.

I went back and looked at the error again, noticed the ModuleNotFoundError contained whitespace between the quotes, and instantly realized what I did. I mistakenly added a space character at the end of %load_ext sql

I feel a little dull not noticing this before, but I suppose that just proves that the smallest detail makes all the difference. :sweat_smile: