Open In App

How to Install ipython-sql package in Jupyter Notebook?

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

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

Requirements:

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.

Open-Jupyter-Notebook

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

!pip3 install ipython-sql

Or

import sys

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

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

Install-ipython-sql

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

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.


Last Updated : 11 Mar, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads