pip install pyodbc failing: error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Please first make sure you have looked at:
- Documentation: https://github.com/mkleehammer/pyodbc/wiki
- Other issues
Environment
To diagnose, we usually need to know the following, including version numbers. On Windows, be sure to specify 32-bit Python or 64-bit:
- Python: 2.7.6
- pyodbc: Latest version
- OS: ubuntu 14.04.5
- DB:
- driver:
Issue
pip install pyodbc --user Collecting pyodbc Using cached pyodbc-4.0.17.tar.gz Building wheels for collected packages: pyodbc Running setup.py bdist_wheel for pyodbc ... error Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-YtLrrj/pyodbc/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 /tmp/tmp5eqhA5pip-wheel- --python-tag cp27: running bdist_wheel running build running build_ext building 'pyodbc' extension creating build creating build/temp.linux-x86_64-2.7 creating build/temp.linux-x86_64-2.7/src x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=4.0.17 -DSQL_WCHART_CONVERT=1 -I/usr/include/python2.7 -c src/textenc.cpp -o build/temp.linux-x86_64-2.7/src/textenc.o -Wno-write-strings cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default] In file included from src/textenc.cpp:2:0: src/pyodbc.h:56:17: fatal error: sql.h: No such file or directory #include <sql.h> ^ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Failed building wheel for pyodbc Running setup.py clean for pyodbc Failed to build pyodbc Installing collected packages: pyodbc Running setup.py install for pyodbc ... error Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-YtLrrj/pyodbc/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-CRLrEJ-record/install-record.txt --single-version-externally-managed --compile --user --prefix=: running install running build running build_ext building 'pyodbc' extension creating build creating build/temp.linux-x86_64-2.7 creating build/temp.linux-x86_64-2.7/src x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPYODBC_VERSION=4.0.17 -DSQL_WCHART_CONVERT=1 -I/usr/include/python2.7 -c src/textenc.cpp -o build/temp.linux-x86_64-2.7/src/textenc.o -Wno-write-strings cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default] In file included from src/textenc.cpp:2:0: src/pyodbc.h:56:17: fatal error: sql.h: No such file or directory #include <sql.h> ^ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-YtLrrj/pyodbc/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-CRLrEJ-record/install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in /tmp/pip-build-YtLrrj/pyodbc/
src/pyodbc.h:56:17: fatal error: sql.h: No such file or directory #include <sql.h> ^
Your machine does not have the ODBC header files installed. You need to do
sudo apt-get install unixodbc-dev
and then try installing pyodbc again.
https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server
Hi,
I already have unixodbc-dev installed on my system. I followed this.
➜ sudo apt-get install unixodbc-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
unixodbc-dev is already the newest version (2.3.1-4.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
And I'm trying to install the latest pyodbc==4.0.22; still getting the same error. Any idea on this?
➜ pip install pyodbc==4.0.22
Collecting pyodbc==4.0.22
Using cached pyodbc-4.0.22.tar.gz
Building wheels for collected packages: pyodbc
Running setup.py bdist_wheel for pyodbc ... error
Complete output from command /home/kabir/envs/etl/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-kp3jjwpo/pyodbc/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 /tmp/tmpqpqsm7h7pip-wheel- --python-tag cp35:
running bdist_wheel
running build
running build_ext
building 'pyodbc' extension
creating build
creating build/temp.linux-x86_64-3.5
creating build/temp.linux-x86_64-3.5/src
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPYODBC_VERSION=4.0.22 -I/usr/include/python3.5m -I/home/kabir/envs/etl/include/python3.5m -c src/buffer.cpp -o build/temp.linux-x86_64-3.5/src/buffer.o -Wno-write-strings
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
In file included from src/buffer.cpp:12:0:
src/pyodbc.h:45:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Failed building wheel for pyodbc
Running setup.py clean for pyodbc
Failed to build pyodbc
Installing collected packages: pyodbc
Running setup.py install for pyodbc ... error
Complete output from command /home/kabir/envs/etl/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-kp3jjwpo/pyodbc/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-4setzddr-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/kabir/envs/etl/include/site/python3.5/pyodbc:
running install
running build
running build_ext
building 'pyodbc' extension
creating build
creating build/temp.linux-x86_64-3.5
creating build/temp.linux-x86_64-3.5/src
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPYODBC_VERSION=4.0.22 -I/usr/include/python3.5m -I/home/kabir/envs/etl/include/python3.5m -c src/buffer.cpp -o build/temp.linux-x86_64-3.5/src/buffer.o -Wno-write-strings
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
In file included from src/buffer.cpp:12:0:
src/pyodbc.h:45:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Command "/home/kabir/envs/etl/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-kp3jjwpo/pyodbc/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-4setzddr-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/kabir/envs/etl/include/site/python3.5/pyodbc" failed with error code 1 in /tmp/pip-build-kp3jjwpo/pyodbc/
I'm using:
- Python 3.5.2
- Ms SQL Server 2017
- Ubuntu 16.04 LTS
Let me know if I need to install any other dependencies.
Anyway, I figured out the issue. I had to install python3-dev on ubuntu (in addition to unixodbc-dev) and it did work.
In case anybody runs into this issue again. Please ensure you've installed these:
➜ sudo apt-get install python3-dev
➜ sudo apt-get install unixodbc-dev
FYI: Python 2.x users, will need python-dev instead.
I'm see the same issue and both python3-dev and unixodbc-dev are installed. I've looked elsewhere and installed every recommended package any other thoughts on how to fix this?
Python 3.6.4 Ubuntu 16.04.2 LTS
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
In file included from src/row.cpp:12:0:
src/pyodbc.h:45:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Strange. I exactly had same issue.
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPYODBC_VERSION=4.0.22 -I/usr/include/python3.5m -I/home/kabir/envs/etl/include/python3.5m -c src/buffer.cpp -o build/temp.linux-x86_64-3.5/src/buffer.o -Wno-write-strings
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
In file included from src/buffer.cpp:12:0:
src/pyodbc.h:45:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
But after installing python3-dev and unixodbc-dev, it got resolved.
Can you make sure you have all these dev packages installed on your system? Not sure if this works, but these include pretty much all the dependencies usually required for python.
➜ sudo apt-get install build-essential libssl-dev libffi-dev python3-dev
➜ sudo apt-get install unixodbc-dev
@neostorm - How did you install Python 3.6 on that machine?
RHEL / CentOS:
yum install unixODBC
yum install unixODBC-devel
using alpine??
for python3.7 run also:
sudo apt-get install python3.7-dev
for python3.7 run also:
sudo apt-get install python3.7-dev
Thanks, It worked.
I have the same issue in Visual Studio Code on Mac OSX while trying to deploy a timer trigger function to Azure Functions. The function works perfectly while executing within VSC, but the deployment fails with the same 'unable to execute gcc' error. I found another issue talking about that, where I've asked for help too, but if anyone watching this issue can help me, I'd be very grateful!
@dxkaufman what you're describing has nothing to do with pyODBC, and that error message is very generic, so it is no surprise you will find issues about it which are completely unrelated to your situation.
@v-chojas For that matter, I seem to have read this post inattentively... I thought it mentioned the gcc error, but now I realize this one has more to do with the presence of code files... my mistake. Thanks for the quick reply.
Might just come down to the version of Python one is using. I was using python 3.6 on ubuntu 14.04, so
sudo apt-get install python3.6-dev
sudo apt-get install unixodbc-dev
python3.6 -m pip install pyodbc
Worked for me.
worked for me on ubuntu 14.04. thanks
@ffedoroff thanks bro, it worked
src/pyodbc.h:56:17: fatal error: sql.h: No such file or directory #include <sql.h> ^
Your machine does not have the ODBC header files installed. You need to do
sudo apt-get install unixodbc-devand then try installing pyodbc again.
Perfectly solved my problem.
on ubuntu 18.04 and python3.7, python3.7 dev was required for me:
sudo apt-get install python3.7-dev
On ubuntu 16.04 and using python3.6 I am still getting the error. But while installing python3.6-dev using the following command sudo apt-get install python3.6-dev I am getting an error
E: Unable to locate package python3.6-dev E: Couldn't find any package by glob 'python3.6-dev' E: Couldn't find any package by regex 'python3.6-dev'
After doing research on it, I found that we could add python3.6-dev package using the following repo:
sudo add sudo add-apt-repository ppa:deadsnakes/ppa -y && sudo apt-get update
But does adding this repo trustworthy?