Open In App
Related Articles

How to Install ipython-sql package in Jupyter Notebook?

Improve Article
Save Article
Like Article

ipython-sql is a %sql magic for python. This is a magic extension that allows you to immediately write SQL queries into code cells and read the results into pandas DataFrames. Using this, we can connect to any database which is supported SQLAlchemy. This is applicable to both classic notebooks and the current Jupyter Labs. In this article, we will see how to install ipython-sql in the Jupyter notebook. 

Installing ipython-sql in Jupyter Notebook


To install the ipython-sql in the Jupyter notebook we have to follow the following steps:

Step 1: Open Jupyter Notebook using the Anaconda Navigator and create a new notebook.


Step 2: Type any one of the following commands in the code cell.

!pip3 install ipython-sql


import sys

!{sys.executable} -m pip install ipython-sql

This will install ipython-sql along with all the necessary dependencies.


Step 3: Enter the following magic command.

%load_ext sql

This will load the SQL module in the notebook. Now, with the use of %sql magic, you can use SQL queries directly in Jupyter Notebook.

Using ipython-sql in Jupyter Notebook


In the above code, I’ve created a STUDENT table and filled it with values. Using ipython-sql, we can easily create tables, connect to existing tables, and write complicated queries.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 11 Mar, 2022
Like Article
Save Article
Similar Reads
Complete Tutorials