Trouble installing pymssql on Windows

2019-05-07 17:18发布

问题:

I can't find great support for pymssql installation support on Windows. I'm trying to connect to an enterprise database through another employee's python wrapper. This wrapper requires my installing of pymssql. The RTFM on this doesn't have very explicit instructions on the installation process of FreeTDS and OpenSSL.

Steps to Install

All downloaded files (FreeTDS and OpenSSL) are from the RTFM link mentioned above. There is mention of adding both downloads to a C:\Program Files folder and adding the binaries into the system PATH, so I did this:

FreeTDS

  1. Downloaded FreeTDS >> created the directory C:\Program Files (x86)\FreeTDS >> copy/paste contents of FreeTDS download into C:\Program Files (x86)\FreeTDS directory >> added C:\Program Files (x86)\FreeTDS into my system's PATH

Contents of FreeTDS download:

\bin
    \bsqldb.exe
    \bsqldb.exe.manifest
    \bsqlodbc.exe
    ...
    \tsql.exe
\include
    \bkpublic.h
    \cspublic.h
    \cstypes.h
    ...
    \tds_sysdep_public.h
\lib
    \static
        \db-lib.lib
        \iconv.lib
        \libct.lib
        \replacements.lib
        \tds.lib
    \ct.dll
    \ct.dll.manifest
    ...
    \tsodbc.lib
\lib-nossl
(same as \lib)

OpenSSL

  1. Downloaded OpenSSL >> created the directory C:\Program Files (x86)\OpenSSL >> copy/paste contents of OpenSSL download into C:\Program Files (x86)\OpenSSL directory >> added C:\Program Files (x86)\OpenSSL into my system's PATH

Contents of OpenSSL download:

\HashInfo.txt
\libeay32.dll
\OpenSSL License.txt
\openssl.exe
\ReadMe.txt
\ssleay32.dll

PYMSSQL

  1. Install pymssql through pip: python -m pip install pymssql >> then check for install status:

Open Python Environment

  • run: import pymssql
  • get: ImportError: DLL load failed: The specified module could not be found.

Super frustrating. Really appreciate any help here!

(unfortunately most everyone I know runs pymssql from Linux and they don't have this problem)

回答1:

As mentioned (briefly) in the pymssql documentation you cited, and also in my related answer here, your Windows PATH needs to include the folder(s) where the DLL files reside, not the base folder(s) for FreeTDS (and OpenSSL, if required).

So, on my test machine running 32-bit Windows my PATH needed to include the "lib-nossl" folder for FreeTDS ...

C:\Users\Gord\Downloads\freetds-v0.95.83-win-x86-vs2015\lib-nossl

... in order for me to use pymssql 2.1.2 with Python 3.5.1 to establish a non-encrypted connection to my SQL Server.