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

南楼画角 提交于 2019-11-28 02:05:06

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.

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"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!