Working in Jupyter Notebooks Locally

Screen Link: https://app.dataquest.io/m/544/guided-project%3A-analyzing-cia-factbook-data-using-sql/2/introduction

My Code:

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

What I expected to happen:
I installed Anaconda and opened Jupyter Notebooks locally. I used the above suggested code from the Guided Project to load SQLite in the Jupyter Notebooks

What actually happened:

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

/opt/anaconda3/lib/python3.8/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
   2328 

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

/opt/anaconda3/lib/python3.8/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)
    188 
    189         if callable(arg):

/opt/anaconda3/lib/python3.8/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)
     34 
     35         if res == 'already loaded':

/opt/anaconda3/lib/python3.8/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. "

/opt/anaconda3/lib/python3.8/importlib/__init__.py in import_module(name, package)
    125                 break
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128 
    129 

/opt/anaconda3/lib/python3.8/importlib/_bootstrap.py in _gcd_import(name, package, level)

/opt/anaconda3/lib/python3.8/importlib/_bootstrap.py in _find_and_load(name, import_)

/opt/anaconda3/lib/python3.8/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

ModuleNotFoundError: No module named 'sql'

Trying to figure out what is going wrong… any ideas what I need to change to get SQLite working locally and connect to the database? I downloaded the factbook.db database and stored it in the same local directory as the Jupyter notebook file

Hello @bc330,

The last line explains it all:

For RDBMS access via jupyter (like %sql), you will need to install ipython-sql.
Since you’re using anaconda, I suggest you install the module in your conda environment.

For some understanding, peek here
For conda installation, read here

Hope it works for you!