PyODBC : can't open the driver even if it exists

后端 未结 7 986
一向
一向 2020-12-31 01:03

I\'m new to the linux world and I want to query a Microsoft SQL Server from Python. I used it on Windows and it was perfectly fine but in Linux it\'s quite painful.

相关标签:
7条回答
  • 2020-12-31 01:17

    had the same issue once.. 1.try conda update libgcc(this is because pyodbc installed through pip and conda look for different versions of the file..)..this might have been fixed ..... link:https://github.com/ContinuumIO/anaconda-issues/issues/1639 look for nehaljwani answer .

    2.also check the version number of the odbc file correctly in /etc/odbcinst.ini and /etc/odbc.ini ...names should match and also the driver path.

    0 讨论(0)
  • 2020-12-31 01:19

    Maybe it is a bit late, but I leave this scripts that worked for me.

    My problem was the same as yours and I tested all the options such as changing the driver location, making a symbolic link, modify /etc/*.ini files, etc... nothing worked.

    My problem, running python 3.6, pyodbc package in a docker container from alpine was the library libssl1.0.0

    Here you will find my installation script for pyodbc Debian 8 (alpine) docker image using the driver v13

    DRIVER={ODBC Driver 13 for SQL Server}

    The command I run for database connection was:

    import pyodbc
    connection_string = 'DRIVER={ODBC Driver 13 for SQL Server};'
    connection_string += 'SERVER={0};DATABASE={1};UID={2};PWD={3};'.format(host,dbname,user,pwd)
    connection = pyodbc.connect(connection_string)
    
    0 讨论(0)
  • 2020-12-31 01:27

    The following suggestions may help to solve the problem:

    • Make sure the drive configuration INI file exists odbcinst -j (check odbcinst.ini).
    • Make sure the filepath to configured driver from your INI file (run: odbcinst -j) exist and has read and executable permission flags (O_RDONLY|O_CLOEXEC).
    • If you still got file not found error, despite the file exists, the problem could be related to libgcc version mismatch as per nehaljwani's GitHub comment. The solution is to update your libgcc by running conda update libgcc command.

      Related: ODBC Driver 13 for SQL Server can't open lib on pyodbc while connecting on AWS E2 ubuntu instance.

    • For macOS, see: Installing ODBC via HomeBrew.

    0 讨论(0)
  • 2020-12-31 01:27

    I solve this problem after installing libssl1.0.0.

    First, I setup my connection string in this way:

        cnxn = pyodbc.connect('DRIVER={/usr/local/lib/libmsodbcsql.13.dylib};   
        SERVER=myServerIP,1433;DATABASE=myDBName;UID=sa;PWD=dbPassword')
    

    Then, I installed libssl1.0.0:

        echo "deb http://security.debian.org/debian-security jessie/updates main" >> /etc/apt/sources.list
        apt-get install libssl1.0.0
    

    Finnaly, I setup the locales:

        apt-get -y install locales 
        echo "en_US.UTF-8 UTF-8" > /etc/locale.gen 
    

    After doing these steps, my python module was able to find and connect to database.

    0 讨论(0)
  • 2020-12-31 01:37

    I also had the same problem on Ubuntu 14 after following the microsoft tutorial for SQL Server Linux ODBC Driver.

    The file exists and after running an ldd, it showed there were dependencies missing:

    /opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.0.0: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version GLIBCXX_3.4.20' not found (required by /opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.0.0) /opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.0.0: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: versionCXXABI_1.3.8' not found (required by

    after searching for a while I found its because Ubuntu's repo didnt have GLIBCXX on version 3.4.20, it was at 3.4.19.

    I then added a repo to Ubuntu, updated it and forced it to upgrade libstdc++6

    sudo add-apt-repository ppa:ubuntu-toolchain-r/test 
    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install libstdc++6
    

    Problem solved, tested with isql:

    +---------------------------------------+
    | Connected!                            |
    |                                       |
    | sql-statement                         |
    | help [tablename]                      |
    | quit                                  |
    |                                       |
    +---------------------------------------+
    SQL> 
    

    After that I tried testing using pdo_odbc (PHP), it then gave me the same driver not found error. To solve this I had to create a symbolic link to fix libodbcinst.so.2:

    sudo ln -s /usr/lib64/libodbcinst.so.2 /lib/x86_64-linux-gnu/libodbcinst.so.2
    
    0 讨论(0)
  • 2020-12-31 01:42

    I found an answer that works for me here. This is for python 2.7 (so may not work for those who are looking for a solution for python 3.x).

    The suggested solution is to update libgcc: 4.8.5-2 --> 5.2.0-0

    For updating libgcc, use this command

    conda update libgcc
    
    0 讨论(0)
提交回复
热议问题