簡體   English   中英

在 Mac 上安裝“pymssql”時出錯 — FreeTDS

[英]Error during install of `pymssql` on Mac — FreeTDS

我已經查看了有關此主題的許多問題,但所有問題似乎都已過時或無濟於事。 我正在嘗試使用pip3 pymssql 我有 python 3.7 版和 freetds 1.1.26 版。 當我在這里運行pip3 install pymssql是我遇到的冗長錯誤。 乍一看,我認為這可能是 freetds 版本的問題(請參見此處),我還嘗試直接從 github 存儲庫安裝: pip3 install git+https://github.com/pymssql/pymssql但輪子未能構建.

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.

可惜pymssql項目已經停產: https://github.com/pymssql/pymssql

如果您需要連接到 SQL 服務器,我建議您使用pyodbc 這是快速版本,看起來您已經完成了 FreeTDS 安裝。

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

然后,在您的連接中明確,因為這解決了大多數問題:

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

pyodbc的完整文檔在這里: https://github.com/mkleehammer/pyodbc/wiki

祝你好運!

在 MacOs 大蘇爾

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM