Trouble connecting to database on Jupyter

Hi. I’m really struggling to connect the database to Jupyter in my SQL guided projects (first the CIA Factbook porject and now Answering Business questions using SQL.

I’m sorry to ask this question as I know that it has been asked multiple times, but I have read through many of the threads about this and still not found a solution.

I have installed ipython-sql, but when I run

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

I get no output.

I have also tried to add this at the top of my notebook (as suggested in another thread) and it says that the commands do not exist:

!dir >output_dir.txt
!where /R C:\ /T *.db >output_dbs.txt

The project and database is in the same location.

I’m at a loss for what else I can try - does anyone by any chance have some other ideas? It works on the DQ Jupyter notebook, just not my local notebook.

Thanks in advance

@harsh.raizada @Rucha @the_doctor @info.victoromondi @otavios.s Kindly anyone solve this query and help the folk out.

hi @veenstramy

What is the output you are expecting here? because even I don’t get any output after executing this command.

Try this code in the next cell and let us know if this gives you an error.

%%sql
SELECT *
  FROM sqlite_master
 WHERE type='table';

And if it gives you a dataframe like structure and this message, you are good to go:

* sqlite:///<database_name>.db
Done. 

Please do mention the OS in case you still get an error. As I use Windows and have no experience with Mac, so will have to highlight it to fellow Mac students.

2 Likes

Thank you so much, @Rucha! I don’t get an error when I run the code, so it obviously does work (I feel silly for not trying this earlier)!

According to this page: https://app.dataquest.io/m/257/guided-project%3A-analyzing-cia-factbook-data-using-sql/2/introduction, I should get the output

'Connected: [email protected]'

On the DQ interface I get it, but not on my local Jupyter and I thought that continuing the SQL wouldn’t work without it. Anyway, I’ll keep going with the project and hopefully I don’t run into any errors around this.

Thanks again!

1 Like

hey @veenstramy

That’s okay.

Well I only did start my first project on DQ’s jupyter env, that too a portion of it. Once I started understanding Jup NB, I shifted to working on my local machine, so I never really noticed this difference.
I just tried it now and yup, it does give the connected message. May be the version is different.

Bruno here suggests the lab and NB difference but we are both using NB’s so really not sure why.