Cannot get my Jupyter Notebook to work for guided SQL project

I am just starting the guided project to analyze CIA Factbook in the SQL Fundamentals course. I downloaded the factbook.db file and it is in my_datasets. It shows up as a file in Jupyter.

I ran the first line of code from step 1:

!conda install -yc conda-forge ipython-sql

and I got this response:

Solving environment: ...working... done

# All requested packages already installed.```

Step two says to then use this code:

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

I copied it in and ran it and nothing happens. 

I am supposed to get:

'Connected: None@factbook.db'

I do not get any result.  I did not have issues with Jupyter for the Python guided projects, but I am not able to get it working for SQL.  Any help would be appreciated.
2 Likes

If you’re using these cell magic in a cell after importing other things, I’d recommend moving these to a separate cell. And are you sure that factbook.db and the notebook are in the same directory?

To be honest, I don’t know. The course did not really go into how to do this. I downloaded the file as directed and copied it to my_datasets folder.

Maybe do I need to extract the separate files? I don’t have a great deal of experience with Jupyter yet, and honestly the Data Quest lessons don’t give a great explanation of how to use it.

1 Like

Did you check their blog about it? https://www.dataquest.io/blog/jupyter-notebook-tutorial/

Anyway my recomendations are:

  1. Create a folder for each project
  2. Inside that folder extract the files
  3. Create the notebook inside that folder, in that way you can open a file by just writing the name

Good luck

Hi @amhackdpt2, depending on your subscription level, you may be able to access content specifically on how to use Jupyter Notebook at: https://app.dataquest.io/m/349/project%3A-learn-and-install-jupyter-notebook/2/running-code.

It was a good primer to go through that not only made guided projects much easier to handle but helped me in writing and testing portions of code on my local jupyter notebook. DQ’s material also teaches quite a bit on “Markdown” to help us write down what we are doing in each cell. That makes old projects easy to refer back to, and remember what we did. I found this useful: https://commonmark.org/help/

Hope this will be helpful.

I’m having same problem.

That blog does not say anything about SQL or how to connect via jupyter

Hi @jamesberentsen,

After making sure that you have installed ipython-sql:
conda install -c conda-forge ipython-sql

Please try the steps mentioned in this post:

Make sure to change the database filename.

Best,
Sahil

1 Like

Thanks, that solved it.

1 Like

Hi. I’m having the exact same problem. I have tried all of the steps on this thread (conda install -c conda-forge ipython-sql, all cell magic code is separate, the files are in the correct folder, etc.) but I’m still not getting any output after running

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

Any other ideas on what I can try? Thanks!

2 Likes

Hi @veenstramy,

That is strange. If ipython-sql is installed and factbook.db is stored in the same location as the notebook file, it should have worked. Can you please send me the output of the following:

conda list | grep ipython-sql

Best,
Sahil

Hi @Sahil, thanks for responding, I’v actually managed to solve this issue :slight_smile:

1 Like

Hi Sahil,

I’m having the exact same problem, when I enter the following I get no output at all:
%%capture
%load_ext sql
%sql sqlite:///factbook.db

I ran what you suggested and the following was the output:

Note: you may need to restart the kernel to use updated packages.

‘grep’ is not recognized as an internal or external command, operable program or batch file.

No idea what to do next, please can you offer advice?

Thanks

Hi,

I am having the same issue. I am trying to do the project using Jupyter on my own computer. The factbook database is in the same folder as my notebook. When I run the code:

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

I get no output.
All the required packages are installed.
After running: conda list | grep ipython-sql
The output showed:

ipython-sql 0.3.9 py38h32f6830_1001 conda-forge

Note: you may need to restart the kernel to use updated packages.

Am I doing something wrong?

Hi @d.meaney19,

If you are still experiencing this issue, can you please send me your notebook file and the database file? I will check it on my end.

Thanks,
Sahil

2 Likes

@Sahil I am having exactly the same issue.

I have tried all the recommended solutions here, yet I don’t seem to get any output.
After running
%%sql SELECT * FROM sqlite_master WHERE type='table';

I get the following output (That’s my notebook file attached)
Guided Project… Analyzing CIA Factbook Data Using SQL.ipynb (2.2 KB)

And running
conda list | grep ipython-sql
gives the following error too:
Note: you may need to restart the kernel to use updated packages. 'grep' is not recognized as an internal or external command, operable program or batch file.

Both my notebook file and the database file are in the same directory and I ran this code
!conda install -yc conda-forge ipython-sql
Which executed successfully.

Please help. Thanks.

Click here to view the jupyter notebook file in a new tab

1 Like

Hi @ifeanyi.akawi85,

Your notebook is working fine on my end! I assume that the factbook.db file was not available in the same directory as your notebook file. Therefore, when you ran:

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

It created an empty factbook.db file.

I have attached a zip file with this reply that contains both your project file and the required database file. Try running it on your end and it will work this time.

257.zip (35.8 KB)

grep command is not available in windows.

Let me know if you need any further help with it. I would be happy to help you.

Best,
Sahil