Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPython Notebook and SQL: 'ImportError: No module named sql' when running '%load_ext sql'

Just set up an IPython Notebook on Ubuntu 16.04 but I can't use %load_ext sql. I get: ImportError: No module named sql

I've tried using pip and pip3 with and without sudo to install ipython-sql. All 4 times it installed without issue but nothing changes on the notebook.

Thanks in advance!

like image 685
user1933275 Avatar asked May 10 '16 22:05

user1933275


2 Answers

If you're trying to connect the IBM database and came across this problem and the above solutions couldn't do it for you, you could give this a chance. (By the way, this error usually means one of your package installations doesn't meet the requirements or more probably: you're in the wrong kernel/virtual environment and the Jupyter instance can't run your command from the specified packages.)

From JupyterLab or Jupyter Notebook go to Kernel>Change Kernel and change the kernel that you've installed the packages. Wait for it to establish a connection. Then use 0, 0 to restart kernel (or Kernel>Restart Kernel

Go to any cell and run the below commands to install packages in the current kernel.

!pip install sqlalchemy==1.3.9
!pip install ibm_db_sa
!pip install ipython-sql

Now try %load_ext sql

like image 107
KHAN Avatar answered Nov 14 '22 23:11

KHAN


I know it's been a long time, but I faced the same issue, and Thomas' advice solved my problem. Just outlining what I did here.

When I ran sys.executable in the notebook I saw /usr/bin/python2, while the pip I used to install the package was /usr/local/bin/pip (to find out what pip you are using, just do which pip or sudo which pip if you are installing packages system-wide). So I reinstalled ipython-sql using the following command, and everything worked out just fine.

sudo -H /usr/bin/python2 -m pip install ipython-sql

This is odd since I always install my packages using pip. I'm wondering maybe there's something special about the magic functions in Jupyter.

like image 5
Ashkan Avatar answered Nov 15 '22 00:11

Ashkan