2

In Jupyter, I am trying to pull sql data through a obdc connection,using pyodbc. I get the below error. I am able to use pyodbc in spyder using python 2. I have tried re-loading pyodbc module from the command line without success. Any ideas?

import pandas as pd
import pyodbc

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-15-b8f1855c5265> in <module>()
      1 import pandas as pd
----> 2 import pyodbc

ModuleNotFoundError: No module named 'pyodbc'
Parfait
  • 104,375
  • 17
  • 94
  • 125
getaglow
  • 343
  • 4
  • 15
  • You might have multiple python installs. Are you using python 2 kernel or python 3 kernel in Jupyter? `pyodbc` may be installed on former and not latter. – Parfait Feb 06 '18 at 15:19
  • Jupyter is a 3, my previous work in spyder is 2. I've seen the suggestion that there may be multiple python installs on the internet. How do I rectify this problem. I have not been able to find directions. Thank you btw – getaglow Feb 06 '18 at 15:58

1 Answers1

5

Essentially, your machine has two version installations of Python. Hence, the module pyodbc corresponds to only one version, 2, and not the other, 3. You can do one of the following:

  1. Add both the Python 2 kernel to your current Jupyter installation. Then, run your needed notebook under Python 2 to have access to all its modules like pyodbc and spyder. See here:

    python2 -m pip install ipykernel
    
    python2 -m ipykernel install --user
    
  2. Install pyodbc for Python 3 such as below command line:

    python3 -m pip install pyodbc
    
Parfait
  • 104,375
  • 17
  • 94
  • 125
  • 1
    Thank you for this guidance. For anyone that comes to this post: When I downloaded and installed Anaconda, it placed Anaconda2 and Anaconda3 in my programs list. I opened the Anaconda Command Prompt in Anaconda3 and installed pyodbc as suggested above (w/o 'python3'). It installed pyodbc, and my Jupyter notebook works! – getaglow Feb 08 '18 at 15:51
  • Great to hear! Glad it all worked out. Now try installing the R kernel for Jupyter is another challenge -of course if you use R =) – Parfait Feb 08 '18 at 16:09