麻烦在 MacOS Mojave 上安装 pymssql

Posted

技术标签:

【中文标题】麻烦在 MacOS Mojave 上安装 pymssql【英文标题】:Troubling installing pymssql on MacOS Mojave 【发布时间】:2018-11-06 13:06:02 【问题描述】:

我已将我的 MAC 操作系统更新到最新版本 (Mojave),并安装了最新版本的 XCode (10.1)。然后我安装了freetds,并使用pip安装了pymssql:

pip install pymssql

但遇到以下错误:

Collecting pymssql
  Using cached https://files.pythonhosted.org/packages/2e/81/99562b93d75f3fc5956fa65decfb35b38a4ee97cf93c1d0d3cb799fffb99/pymssql-2.1.4.tar.gz
Building wheels for collected packages: pymssql
  Running setup.py bdist_wheel for pymssql ... error
  Complete output from command /Users/dreamteam/anaconda/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/n5/z6rt8r7157vfmnp53_362dbm0000gn/T/pip-install-GRuqJN/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/n5/z6rt8r7157vfmnp53_362dbm0000gn/T/pip-wheel-dIWT59 --python-tag cp27:
  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
  building '_mssql' extension
  creating build
  creating build/temp.macosx-10.5-x86_64-2.7
  creating build/temp.macosx-10.5-x86_64-2.7/src
  gcc -fno-strict-aliasing -I/Users/dreamteam/anaconda/include -arch x86_64 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/Users/dreamteam/anaconda/include/python2.7 -c src/_mssql.c -o build/temp.macosx-10.5-x86_64-2.7/src/_mssql.o -DMSDBLIB
  src/_mssql.c:30443:32: warning: unused function '__Pyx_PyUnicode_FromString' [-Wunused-function]
  static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) 
                                 ^
  src/_mssql.c:332:29: warning: unused function '__Pyx_Py_UNICODE_strlen' [-Wunused-function]
  static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
                              ^
  src/_mssql.c:30620:33: warning: unused function '__Pyx_PyInt_FromSize_t' [-Wunused-function]
  static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) 
                                  ^
  src/_mssql.c:29177:27: warning: function '__Pyx_PyInt_As_long' is not needed and will not be emitted [-Wunneeded-internal-declaration]
  static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) 
                            ^
  src/_mssql.c:29361:27: warning: function '__Pyx_PyInt_As_char' is not needed and will not be emitted [-Wunneeded-internal-declaration]
  static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *x) 
                            ^
  5 warnings generated.
  creating build/lib.macosx-10.5-x86_64-2.7
  gcc -bundle -undefined dynamic_lookup -L/Users/dreamteam/anaconda/lib -arch x86_64 -arch x86_64 build/temp.macosx-10.5-x86_64-2.7/src/_mssql.o -L/usr/local/lib -L/Users/dreamteam/anaconda/lib -lsybdb -o build/lib.macosx-10.5-x86_64-2.7/_mssql.so
  ld: library not found for -lgcc_s.10.5
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  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
    Complete output from command /Users/dreamteam/anaconda/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/n5/z6rt8r7157vfmnp53_362dbm0000gn/T/pip-install-GRuqJN/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/n5/z6rt8r7157vfmnp53_362dbm0000gn/T/pip-record-xd5_kP/install-record.txt --single-version-externally-managed --compile:
    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
    building '_mssql' extension
    creating build
    creating build/temp.macosx-10.5-x86_64-2.7
    creating build/temp.macosx-10.5-x86_64-2.7/src
    gcc -fno-strict-aliasing -I/Users/dreamteam/anaconda/include -arch x86_64 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/Users/dreamteam/anaconda/include/python2.7 -c src/_mssql.c -o build/temp.macosx-10.5-x86_64-2.7/src/_mssql.o -DMSDBLIB
    src/_mssql.c:30443:32: warning: unused function '__Pyx_PyUnicode_FromString' [-Wunused-function]
    static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) 
                                   ^
    src/_mssql.c:332:29: warning: unused function '__Pyx_Py_UNICODE_strlen' [-Wunused-function]
    static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
                                ^
    src/_mssql.c:30620:33: warning: unused function '__Pyx_PyInt_FromSize_t' [-Wunused-function]
    static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) 
                                    ^
    src/_mssql.c:29177:27: warning: function '__Pyx_PyInt_As_long' is not needed and will not be emitted [-Wunneeded-internal-declaration]
    static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) 
                              ^
    src/_mssql.c:29361:27: warning: function '__Pyx_PyInt_As_char' is not needed and will not be emitted [-Wunneeded-internal-declaration]
    static CYTHON_INLINE char __Pyx_PyInt_As_char(PyObject *x) 
                              ^
    5 warnings generated.
    creating build/lib.macosx-10.5-x86_64-2.7
    gcc -bundle -undefined dynamic_lookup -L/Users/dreamteam/anaconda/lib -arch x86_64 -arch x86_64 build/temp.macosx-10.5-x86_64-2.7/src/_mssql.o -L/usr/local/lib -L/Users/dreamteam/anaconda/lib -lsybdb -o build/lib.macosx-10.5-x86_64-2.7/_mssql.so
    ld: library not found for -lgcc_s.10.5
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command 'gcc' failed with exit status 1

    ----------------------------------------

我尝试过链接 freetds 软件包,但没有成功。此错误与 XCode 版本有关吗?如何解决? (Python版本为2.7)

【问题讨论】:

【参考方案1】:

此错误似乎与最新版本的 XCode 有关。我安装了旧版本的 XCode(9.4),然后成功安装了 pymssql。

【讨论】:

【参考方案2】:

打开终端 安装 Homebrew 包管理器

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 

安装 FreeTDS 模块

brew install FreeTDS  

安装 pymssql 模块

pip3 install pymssql

希望这对你们有帮助。

【讨论】:

以上是关于麻烦在 MacOS Mojave 上安装 pymssql的主要内容,如果未能解决你的问题,请参考以下文章

sh 在macOS Mojave上重新安装Brew的XCode命令行工具

在 MacOs Mojave 上安装 xdebug - 找不到“php.h”文件

Valgrind 不能在 MacOS Mojave 上运行?与康达一起安装

无法在 Mojave 上安装 XCode

在 macOS Mojave 10.14.5 上安装 python3-pip / flask [重复]

在 MacOS Mojave 上为 QGIS 安装 Python 3.6