簡體   English   中英

mac - pip 安裝 pymssql 錯誤

[英]mac - pip install pymssql error

我使用 Mac (OS X 10.11.5)。 我想為python安裝模塊pymssql Terminal.app ,我輸入sudo -H pip install pymssqlpip install pymssqlsudo pip install pymssql 但是出現錯誤。

目錄/Users/janghyunsoo/Library/Caches/pip/http或其父目錄不屬於當前用戶所有,緩存已禁用。 請檢查該目錄的權限和所有者。 如果使用sudo執行pip ,您可能需要sudo-H標志。

目錄/Users/janghyunsoo/Library/Caches/pip或其父目錄不屬於當前用戶所有,並且緩存輪已禁用。 檢查該目錄的權限和所有者。 如果使用sudo執行pip ,您可能需要sudo-H標志。

Collecting pymssql
  Downloading pymssql-2.1.2.tar.gz (898kB)
    100% |████████████████████████████████| 901kB 955kB/s 
Installing collected packages: pymssql
  Running setup.py install for pymssql ... error
    Complete output from command /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-KA5ksi/pymssql/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-A3wRBy-record/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', '/opt/local/include', '/opt/local/include/freetds']
    setup.py: library_dirs = ['/usr/local/lib', '/opt/local/lib']
    running install
    running build
    running build_ext
    building '_mssql' extension
    creating build
    creating build/temp.macosx-10.6-intel-2.7
    /usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/local/include -I/opt/local/include -I/opt/local/include/freetds -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mssql.c -o build/temp.macosx-10.6-intel-2.7/_mssql.o -DMSDBLIB
    _mssql.c:18924:15: error: use of undeclared identifier 'DBVERSION_80'
        __pyx_r = DBVERSION_80;
                  ^
    1 error generated.
    error: command '/usr/bin/clang' failed with exit status 1
    
    ----------------------------------------
Command "/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-KA5ksi/pymssql/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-A3wRBy-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-build-KA5ksi/pymssql/

最高投票的解決方案對我不起作用,因為 brew 沒有自己鏈接舊版本的 freetds。 我這樣做是為了解決問題:

brew unlink freetds; 
brew install freetds@0.91;
brew link --force freetds@0.91

在運行 pip install 之前,我能夠通過 Homebrew 恢復到舊版本的 FreeTDS 來解決這個問題。

brew unlink freetds; brew install homebrew/versions/freetds091

解決方案是由 andrewmwhite 在以下位置找到的: https : //github.com/pymssql/pymssql/issues/432

http://gree2.github.io/python/setup/2017/04/19/python-instal-pymssql-on-mac上逐步安裝 pymssql 找到了詳細而簡單的答案。

  1. brew unlink freetds; brew install homebrew/core/freetds091
  2. brew link --force freetds@0.91
  3. pip install pymssql

找到了 pip/python2 和 pip3/python3 的解決方案

問題:

在@siva & @himanshu 解決方法適用於python2但不適用於python3我無法從 pip3 成功構建。

pip3 install pymssql

    ..._mssql.c:21155:15: error: use of undeclared identifier 'DBVERSION_80'
        __pyx_r = DBVERSION_80;
                  ^
    1 error generated.
    error: command 'clang' failed with exit status 1

您的問題不是權限問題,而是pymssql依賴代碼的代碼編譯問題。

這是討論,我在 github 上找到解決方案的地方。

在這一點上它已經存在了一段時間,只是為了可見而放置在這里。

只需使用來自 gitub 的最新版本的 pymssql:

    pip3 install git+https://github.com/pymssql/pymssql

也適用於 python2

    pip install git+https://github.com/pymssql/pymssql

    pip2 install git+https://github.com/pymssql/pymssql

我在Mac OS X (10.13.6) & Homebrew (1.7.1-62-gddbefee)多次。 該命令適用於 freetds (0.91) 或 (1.00.94) 的兩個版本

“brew install homebrew/python/pymssql”也可以使用,但截至今天將安裝較舊的 2.1.1。

這在 mac 上對我有用:

pip install cython

那么

pip install git+https://github.com/pymssql/pymssql.git

以上所有解決方案都運行良好。 提醒一句,pymssql pip install pymssql 的 setup.py 期望 Homebrew 已在您機器上的/sw安裝了 Freetds。

我的機器不是這種情況,所以我不得不在這里使用工作:

  1. 手動下載 pymssql 的 .tar 文件
  2. 打開setup.py
  3. 編輯變量fink以將路徑添加到您的計算機上實際安裝 Freetds 的位置。
if sys.platform == 'darwin':
     fink = '<path to Freetds on your Machine>' 
  1. 然后運行python setup.py install

暫無
暫無

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

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