mac – pip install pymssql error

Question:

I use Mac (OS X 10.11.5). I want to install module pymssql for python.
In Terminal.app, I input sudo -H pip install pymssql, pip install pymssql, sudo pip install pymssql . But error occur.

The directory /Users/janghyunsoo/Library/Caches/pip/http or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo‘s -H flag.

The directory /Users/janghyunsoo/Library/Caches/pip or its parent directory is not owned by the current user and caching wheels has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo‘s -H flag.

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('rn', '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('rn', '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/
Asked By: 장현수

||

Answers:

I was able to work around this by reverting to an older version of FreeTDS through Homebrew before running the pip install.

brew unlink freetds; brew install homebrew/versions/freetds091

The solution was found by andrewmwhite at:
https://github.com/pymssql/pymssql/issues/432

Answered By: KennyMonster

“brew install homebrew/python/pymssql” also worked but will install older 2.1.1 as of today.

Answered By: azuruce

The top voted solution did not work for me as brew did not link the older version of freetds on its own. I did this to solve the problem:

brew unlink freetds; 
brew install [email protected];
brew link --force [email protected]
Answered By: Sivadesh

Found Detailed and simple answer with step by step installation of pymssql on http://gree2.github.io/python/setup/2017/04/19/python-instal-pymssql-on-mac.

  1. brew unlink freetds; brew install homebrew/core/freetds091
  2. brew link --force [email protected]
  3. pip install pymssql
Answered By: Himanshu dua

Found a solution for pip/python2 & pip3/python3

Problem:

I was Unable to get a successful build from pip3 following @siva & @himanshu workaround works for python2 but not for python3.

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

Your issue is not a permission issue, but, a code-compiling issue with dependent code for pymssql.

Here’s the discussion,
Where I found the Solution on github.

It has been around for a while at this point, just placing here for visibility.

Just use the newest build of pymssql from gitub:

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

Also works for python2

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

OR

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

I Tested on Mac OS X (10.13.6) & Homebrew (1.7.1-62-gddbefee) multiple times.
The command works for both versions of freetds (0.91) or (1.00.94)

Answered By: JayRizzo

This worked for me on mac:

pip install cython

then

pip install git+https://github.com/pymssql/pymssql.git
Answered By: Siddhant Tanpure

All the solutions above work well . Just one word of caution , the setup.py for pymssql pip install pymssql expects that Homebrew has installed Freetds at /sw on your machine.

This was not the case in my machine so I had to use the work around here :

  1. Manually download the .tar file for pymssql
  2. Open setup.py
  3. Edit the variable fink to add the path to where ever Freetds is actually installed on your machine.
if sys.platform == 'darwin':
     fink = '<path to Freetds on your Machine>' 
  1. Then run python setup.py install
Answered By: Gaurav Chawla
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.