繁体   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