“ImportError: DLL load failed” when trying to import pymssql on Windows

前端 未结 3 775
囚心锁ツ
囚心锁ツ 2020-12-07 03:38

I\'m trying to use the example code from here:

http://www.pymssql.org/en/latest/pymssql_examples.html

I installed the pymmsql module using pip.

相关标签:
3条回答
  • 2020-12-07 04:09

    Update

    Due to negative feedback from the user community regarding the 2.1.2 change, pymssql 2.1.3 and later have reverted to having pip install pymssql distribute pre-compiled wheel files that are statically linked to FreeTDS without SSL support.

    Therefore if you need SSL support then you still cannot simply do pip install pymssql. For Windows you'll need to follow the procedure below, or for Linux you'll need to build pymssql (and possibly FreeTDS) from source using a procedure like the one described in the answers to this question


    Version 2.1.2 of pymssql introduced a significant change in the way it needs to be set up on Windows. Previous versions were distributed with FreeTDS statically linked so all we needed to do was install pymssql (e.g., pip install pymssql) and it "just worked", but SSL connections were not supported.

    Beginning with pymssql version 2.1.2, pymssql is dynamically linked with FreeTDS on Windows and does not ship with the required components of FreeTDS (and OpenSSL, if required). We can still install pymssql itself using pip install pymssql, but that may no longer be sufficient. If we don't already have a working installation of FreeTDS on the Windows machine then we have to download the components ourselves.

    The download links can be found on the pymssql documentation page here:

    pymssql - Docs - FreeTDS - Installation - Windows.

    If an SSL connection is not required then we just have to download the FreeTDS components and ensure that the contents of the "lib-nossl" folder can be found by searching the Windows PATH.

    If an SSL connection is required then we have to download both the FreeTDS and OpenSSL components and ensure that the appropriate DLLs (in the "lib" folder for FreeTDS, and in the "bin" or "bin64" folder for OpenSSL) can be located by searching the Windows PATH.

    Note that these changes affect both new installs and upgrades of pymssql. It has been reported that simply upgrading pymssql from version 2.1.1 to version 2.1.2 will break pymssql on Windows until the required components of FreeTDS (and OpenSSL, if required) are downloaded.

    0 讨论(0)
  • 2020-12-07 04:09

    Nowadays I recommend just downloading the version you need from here https://www.lfd.uci.edu/~gohlke/pythonlibs/#pymssql and then installing via below steps.

    1. Download the version to want to place on disk, can be Downloads or anywhere you want. I downloaded pymssql-2.1.4-cp38-cp38-win_amd64.whl because I'm using Python 3.8 on Windows 10 64 bit.
    2. Navigate to directory where you downloaded or move the file...
    3. pip install <pymssql file name>

    I didn't have to install anything extra, worked right out of the box.

    0 讨论(0)
  • 2020-12-07 04:15

    I had this issue. The simplest solution for me was just to uninstall 2.1.2 then install 2.1.1:

    pip uninstall pymssql

    pip install "pymssql==2.1.1"

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