简体   繁体   中英

Error during install of `pymssql` on Mac — FreeTDS

I have reviewed numerous questions on this topic but all seem either out of date or unhelpful. I am attempting to set up pymssql using pip3 . I have python version 3.7 and freetds version 1.1.26. When I run pip3 install pymssql here is the lengthy error I encounter. At first glance I thought it could be an issue with the freetds version ( see here ) and I also tried installing directly from the github repo: pip3 install git+https://github.com/pymssql/pymssql but the wheel failed to build.

Collecting pymssql
  Using cached pymssql-2.1.4.tar.gz (691 kB)
Building wheels for collected packages: pymssql
  Building wheel for pymssql (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/ty/b0h4wy9938vbwh98tn_r9ryh0000gn/T/pip-install-2jerl6n6/pymssql/setup.py'"'"'; __file__='"'"'/private/var/folders/ty/b0h4wy9938vbwh98tn_r9ryh0000gn/T/pip-install-2jerl6n6/pymssql/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/ty/b0h4wy9938vbwh98tn_r9ryh0000gn/T/pip-wheel-tfqq1pua
       cwd: /private/var/folders/ty/b0h4wy9938vbwh98tn_r9ryh0000gn/T/pip-install-2jerl6n6/pymssql/
  Complete output (35 lines):
  setup.py: platform.system() => 'Darwin'
  setup.py: platform.architecture() => ('64bit', '')
  setup.py: platform.libc_ver() => ('', '')
  setup.py: Detected Darwin/Mac OS X.
      You can install FreeTDS with Homebrew or MacPorts, or by downloading
      and compiling it yourself.

      Homebrew (http://brew.sh/)
      --------------------------
      brew install freetds

      MacPorts (http://www.macports.org/)
      -----------------------------------
      sudo port install freetds

  setup.py: Not using bundled FreeTDS
  setup.py: include_dirs = ['/usr/local/include']
  setup.py: library_dirs = ['/usr/local/lib']
  running bdist_wheel
  running build
  running build_ext
  cythoning src/_mssql.pyx to src/_mssql.c
  /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /private/var/folders/ty/b0h4wy9938vbwh98tn_r9ryh0000gn/T/pip-install-2jerl6n6/pymssql/src/_mssql.pxd
    tree = Parsing.p_module(s, pxd, full_module_name)
  warning: src/_mssql.pyx:150:4: Exception already a builtin Cython type
  cythoning src/pymssql.pyx to src/pymssql.c
  /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /private/var/folders/ty/b0h4wy9938vbwh98tn_r9ryh0000gn/T/pip-install-2jerl6n6/pymssql/src/pymssql.pyx
    tree = Parsing.p_module(s, pxd, full_module_name)
  building '_mssql' extension
  creating build
  creating build/temp.macosx-10.9-x86_64-3.7
  creating build/temp.macosx-10.9-x86_64-3.7/src
  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -I/usr/local/include -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c src/_mssql.c -o build/temp.macosx-10.9-x86_64-3.7/src/_mssql.o -DMSDBLIB
  xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for pymssql
  Running setup.py clean for pymssql
Failed to build pymssql
Installing collected packages: pymssql
    Running setup.py install for pymssql ... error
    ERROR: Command errored out with exit status 1:
     command: /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/ty/b0h4wy9938vbwh98tn_r9ryh0000gn/T/pip-install-2jerl6n6/pymssql/setup.py'"'"'; __file__='"'"'/private/var/folders/ty/b0h4wy9938vbwh98tn_r9ryh0000gn/T/pip-install-2jerl6n6/pymssql/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/ty/b0h4wy9938vbwh98tn_r9ryh0000gn/T/pip-record-tjfo0sbt/install-record.txt --single-version-externally-managed --compile --install-headers /Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pymssql
         cwd: /private/var/folders/ty/b0h4wy9938vbwh98tn_r9ryh0000gn/T/pip-install-2jerl6n6/pymssql/
    Complete output (35 lines):
    setup.py: platform.system() => 'Darwin'
    setup.py: platform.architecture() => ('64bit', '')
    setup.py: platform.libc_ver() => ('', '')
    setup.py: Detected Darwin/Mac OS X.
        You can install FreeTDS with Homebrew or MacPorts, or by downloading
        and compiling it yourself.

        Homebrew (http://brew.sh/)
        --------------------------
        brew install freetds

        MacPorts (http://www.macports.org/)
        -----------------------------------
        sudo port install freetds

    setup.py: Not using bundled FreeTDS
    setup.py: include_dirs = ['/usr/local/include']
    setup.py: library_dirs = ['/usr/local/lib']
    running install
    running build
    running build_ext
    cythoning src/_mssql.pyx to src/_mssql.c
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /private/var/folders/ty/b0h4wy9938vbwh98tn_r9ryh0000gn/T/pip-install-2jerl6n6/pymssql/src/_mssql.pxd
      tree = Parsing.p_module(s, pxd, full_module_name)
    warning: src/_mssql.pyx:150:4: Exception already a builtin Cython type
    cythoning src/pymssql.pyx to src/pymssql.c
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /private/var/folders/ty/b0h4wy9938vbwh98tn_r9ryh0000gn/T/pip-install-2jerl6n6/pymssql/src/pymssql.pyx
      tree = Parsing.p_module(s, pxd, full_module_name)
    building '_mssql' extension
    creating build
    creating build/temp.macosx-10.9-x86_64-3.7
    creating build/temp.macosx-10.9-x86_64-3.7/src
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -I/usr/local/include -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c src/_mssql.c -o build/temp.macosx-10.9-x86_64-3.7/src/_mssql.o -DMSDBLIB
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/ty/b0h4wy9938vbwh98tn_r9ryh0000gn/T/pip-install-2jerl6n6/pymssql/setup.py'"'"'; __file__='"'"'/private/var/folders/ty/b0h4wy9938vbwh98tn_r9ryh0000gn/T/pip-install-2jerl6n6/pymssql/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/ty/b0h4wy9938vbwh98tn_r9ryh0000gn/T/pip-record-tjfo0sbt/install-record.txt --single-version-externally-managed --compile --install-headers /Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pymssql Check the logs for full command output.

Unfortunately, the pymssql project has been discontinued: https://github.com/pymssql/pymssql

I would recommend using pyodbc if you need to connect to SQL Server. Here's the quick version, and it looks like you've already done the FreeTDS installation.

brew install freetds
python3 -m venv pyodbc_venv
source pyodbc_venv/bin/activate
pip install pyodbc

Then, be explicit in your connection, as this solved most problems:

conn = pyodbc.connect('DRIVER={FreeTDS};SERVER=yourserver.yourcompany.com;PORT=1433;DATABASE=yourdb;UID=user;PWD=password;TDS_Version=7.3')

Full docs for pyodbc are here: https://github.com/mkleehammer/pyodbc/wiki

Good luck!

On MacOs Big Sur

brew install freetds openssl
export LDFLAGS="-L/opt/homebrew/opt/freetds/lib -L/opt/homebrew/opt/openssl@1.1/lib"
export CFLAGS="-I/opt/homebrew/opt/freetds/include"
pip3 install pymssql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM