Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install pymssql on MacOS Sierra

Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-J1I0ox/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 /tmp/pip-qmtdBW-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-build-J1I0ox/pymssql/

I am having the same error as displayed here . I followed the instructions on that page by trying brew install freetds followed by sudo -H pip install pymssql.

That generates this error code:

    _mssql.c:18814:15: error: use of undeclared identifier 'DBVERSION_80'
    __pyx_r = DBVERSION_80;
              ^
4 warnings and 1 error generated.
error: command 'cc' failed with exit status 1

----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-J1I0ox/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 /tmp/pip-qmtdBW-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-build-J1I0ox/pymssql/

Searching this error brought me to this page. I followed the solution posted there by trying both brew unlink freetds; brew install homebrew/versions/freetds091 and brew uninstall freetds; brew install homebrew/versions/freetds091 which generates a different error when trying sudo -H pip install pymssql:

_mssql.c:266:10: fatal error: 'sqlfront.h' file not found
#include "sqlfront.h"
         ^
1 error generated.
error: command 'cc' failed with exit status 1

----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/_s/27xppw4j3yl78c9l4v1w3n9m0000gn/T/pip-build-97A9sQ/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 /var/folders/_s/27xppw4j3yl78c9l4v1w3n9m0000gn/T/pip-0nUZo4-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/_s/27xppw4j3yl78c9l4v1w3n9m0000gn/T/pip-build-97A9sQ/pymssql/

So then I gave up and tried to install pyodbc, but I still get similar errors: src/pyodbc.h:56:10: fatal error: 'sql.h' file not found #include sql.h

Any help with this would be great.

like image 523
binzabinza Avatar asked Jul 06 '17 20:07

binzabinza


2 Answers

As of Feb 2021

I can no longer install [email protected] as homebrew does not have it available. The current version of freetds is 1.2.18 and brew link --force freetds doesn't seem to change anything.

The root issue 'sqlfront.h' file not found is due to the freetds files not linking properly during installation. We can fix this by doing

export LDFLAGS="-L/opt/homebrew/opt/freetds/lib"
export CPPFLAGS="-I/opt/homebrew/opt/freetds/include"
pip install pymssql

Where /opt/homebrew/opt/freetds is where homebrew installed freetds on your system (I am on Apple Silicon) and may be different for you. If you are on Intel your's might look something like /usr/local/opt/freetds.

To find exactly where homebrew installed freetds (or any program for that matter) on your system, you can do

brew --prefix freetds

This should return something like /opt/homebrew/opt/freetds or /opt/homebrew/opt/[email protected]. You can ignore any version numbers and append /lib and /include to get the paths you need.

This is a handy trick to keep in mind as it is applicable to lots of other install issues with dependencies installed via homebrew.

like image 32
McFizz Avatar answered Oct 05 '22 14:10

McFizz


This link ended up solving my problem. For anyone else having these issues, this sequence of commands worked for me.

brew uninstall --force freetds
brew install [email protected]
brew link --force [email protected]
pip install pymssql
like image 76
binzabinza Avatar answered Oct 05 '22 15:10

binzabinza