1

When trying to import pyodbc i get the below error. How do I resolve this? All other things I have found on here has not worked. I have also tried everything on this site: https://medium.com/@mauridb/how-to-check-your-anaconda-version-c092400c9978 when it comes to updating the anaconda version (which has only been installed for 30 days on this computer).

I have also tried the below code, and I still get the same error on import. Any assistance would be great.

pip install pyodbc --force-reinstall

I am using:

Python 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] Type "copyright", "credits" or "license" for more information. Spyder 4.0.1 from Anaconda Navigator 1.9.7 on a windows 10 PC

import pyodbc ImportError: DLL load failed: The specified module could not be found.

Sven
  • 301
  • 2
  • 18

2 Answers2

0

Using pypyodbc package worked instead. The connection strings are the same as pyodbc. Call the SQL code with:

import pandas as pd
import pypyodbc

conn = pypyodbc.connect('Driver'={SQL Server};' 
                        'Server=Server;' 
                        'Database=database;
                        'Trusted_Connection=yes;') 

pd.read_sql_query('''SQL CODE''', conn)

It was very important to not use any pace in the connection string where the equal (=) signs are. Not sure why this is.

Sven
  • 301
  • 2
  • 18
  • 1
    pypyodbc is no longer being actively developed or supported. A better solution is to use pyodbc with the latest version of the Microsoft C++ redistributable package. More details [on GitHub](https://github.com/mkleehammer/pyodbc/issues/663#issuecomment-569365502). – Gord Thompson Jan 13 '20 at 13:19
  • This did not work, though it was something I had not tried. Thank you for letting me know that pypyodbc is outdated. I will need to figure this out then. – Sven Jan 13 '20 at 13:37
  • Failure to load a DLL is often because the DLL is a different bitness (32-bit vs 64-bit) from the interpreter. It is easy to have 2 versions of Python installed without being aware of it, and if you do, i is likely that the `pip` you are running is a different bitness from thee interpreter. Just invoking `pip` from the command line means that you are getting whichever one is first in the path. – BoarGules Jan 13 '20 at 13:58
  • @BoarGules, can you please inform on how one would go about checking for this and correcting this? – Sven Jan 14 '20 at 13:49
  • You can find out if you have more than one copy of `pip.exe` using the command `where pip`. Navigate to the folder where the installation of Python that you are expecting to use lives. This will normally be `Python3x`. Then go to its `Scripts` subfolder. The `pip.exe` in that folder is the correct one for the installation, which may not be the one you get when you just type `pip` at the command line. To find out what that command line does, type `pip --version`. It will tell you the version of `pip`, its location on disk, and which version of Python it belongs to. – BoarGules Jan 14 '20 at 14:01
0

I had the same problem and work to me when I installed the latest supported Visual C++. You can do a download in link bellow: https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads

I found this solution from the link bellow, where other people had the problem too. https://github.com/mkleehammer/pyodbc/issues/663

Marcelo Abreu
  • 129
  • 1
  • 2