Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pip install pyodbc failing: error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 #276

Closed
wondernath opened this issue Aug 31, 2017 · 39 comments

Comments

@wondernath
Copy link

Please first make sure you have looked at:

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/

@gordthompson
Copy link
Collaborator

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.

@fenchu
Copy link

fenchu commented Sep 5, 2017

https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server

@kabirbaidhya
Copy link

kabirbaidhya commented Feb 26, 2018

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.

@kabirbaidhya
Copy link

kabirbaidhya commented Feb 26, 2018

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.

@neostorm
Copy link

neostorm commented Mar 1, 2018

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

@kabirbaidhya
Copy link

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

@gordthompson
Copy link
Collaborator

@neostorm - How did you install Python 3.6 on that machine?

@carlosmarin
Copy link

RHEL / CentOS:

yum install unixODBC
yum install unixODBC-devel

@ikwijaya
Copy link

using alpine??

@ffedoroff
Copy link

for python3.7 run also:
sudo apt-get install python3.7-dev

@luissamano
Copy link

for python3.7 run also:
sudo apt-get install python3.7-dev

Thanks, It worked.

@dxkaufman
Copy link

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!

@v-chojas
Copy link
Contributor

@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.

@dxkaufman
Copy link

@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.

@rskelley9
Copy link

rskelley9 commented May 2, 2019

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.

@sumitkarn
Copy link

worked for me on ubuntu 14.04. thanks

@arihantsoganijain
Copy link

@ffedoroff thanks bro, it worked

@yhhzsd
Copy link

yhhzsd commented Feb 17, 2020

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.

Perfectly solved my problem.

@karlkaebnick
Copy link

on ubuntu 18.04 and python3.7, python3.7 dev was required for me:

sudo apt-get install python3.7-dev

@Sameer-Keluskar
Copy link

Sameer-Keluskar commented Mar 20, 2020

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?

@gordthompson
Copy link
Collaborator

deadsnakes has been around for a long time and I've never seen anyone suggest that it is not trustworthy. However, the ultimate decision of whether or not to trust a third-party repo is up to you.

@epomatti
Copy link

This worked for me:

sudo apt-get install python3.8-dev

@durgaamar
Copy link

durgaamar commented May 27, 2020

Hi,
I'm trying to build a docker image using DockerDesktop <Window 10 OS> of my Python3.7 project.
I created a Dockerfile and requirements.txt file. Trying to build the docker image but end-up with pyodbc issue as below:
Please suggest what all changes required in my dockerfile to resolve the issue.
Dockerfile

FROM python:3.7-slim
RUN apt-get update
RUN apt-get install -y --no-install-recommends build-essential gcc

RUN mkdir /app
WORKDIR /app

COPY requirements.txt ./
RUN pip install -r requirements.txt
COPY . /app

EXPOSE 8080
CMD ...

Building wheel for pyodbc (setup.py): started
Building wheel for pyodbc (setup.py): finished with status 'error'
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-v4_phc4e/pyodbc/setup.py'"'"'; file='"'"'/tmp/pip-install-v4_phc4e/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/pip-wheel-o1oir3_4
cwd: /tmp/pip-install-v4_phc4e/pyodbc/
Complete output (14 lines):
running bdist_wheel
running build
running build_ext
building 'pyodbc' extension
creating build
creating build/temp.linux-x86_64-3.7
creating build/temp.linux-x86_64-3.7/src
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DPYODBC_VERSION=4.0.30 -I/usr/local/include/python3.7m -c src/buffer.cpp -o build/temp.linux-x86_64-3.7/src/buffer.o -Wno-write-strings
In file included from src/buffer.cpp:12:
src/pyodbc.h:56:10: fatal error: sql.h: No such file or directory
#include <sql.h>
^~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1

ERROR: Failed building wheel for pyodbc
Running setup.py clean for pyodbc
Building wheel for visitor (setup.py): started
Building wheel for visitor (setup.py): finished with status 'done'

@v-chojas
Copy link
Contributor

That looks like Linux, not Windows; and the solution is to install unixodbc-dev, which has the header files for unixODBC.

@konidala
Copy link

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

This issue is happening when we try to install pyodbc in virtual environment.

@v-chojas
Copy link
Contributor

If you are using Python 3, make sure that you are not running the installation in Python 2.

@ronak2303
Copy link

i am getting same error. i have installed all
yum install -y python-devel yum install -y unixodbc-devel yum install -y gcc yum install -y gcc.c++
environment.
python2.6 with redhat 7.7
installed python3 recently as pip was not avaiable.

when i install pyodbc i used pip3 , as pip is not available on my machine.
pip3 install pyodbc

but still error as below on python.h ...

any help here.

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/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-3j7ta5c5/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-ya39qg9u-record/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_ext
building 'pyodbc' extension
creating build
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/src
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPYODBC_VERSION=4.0.30 -I/usr/include/python3.6m -c src/buffer.cpp -o build/temp.linux-x86_64-3.6/src/buffer.o -Wno-write-strings -DHAVE_UNISTD_H -DHAVE_PWD_H -DHAVE_SYS_TYPES_H -DHAVE_LONG_LONG -DSIZEOF_LONG_INT=8 -I/usr/include
In file included from src/buffer.cpp:12:0:
src/pyodbc.h:45:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
error: command 'gcc' failed with exit status 1

@zombozo
Copy link

zombozo commented Oct 12, 2020

src / pyodbc.h: 56: 17: error fatal: sql.h: No existe tal archivo o directorio
#include <sql.h>
^

Su máquina no tiene instalados los archivos de encabezado ODBC. Necesitas hacer

sudo apt-get install unixodbc-dev

y luego intente instalar pyodbc nuevamente.

un crack, esto me soluciono, todo empezó al utilizar mal un comando remove, tengan cuidado! ahahah

@4revalo
Copy link

4revalo commented Nov 12, 2020

You have to update your python repository by installing yum install python3-devel

@hol-workshop
Copy link

bloody hell, this was required yum install python3-devel
after that pip install pyodbc
finally 4revalo

@akristic
Copy link

This helped me from doccuments site:
https://github.com/mkleehammer/pyodbc/wiki/Install
Ubuntu 18.04
On Ubuntu systems, all you need to do is run

sudo apt install python3-pip
sudo apt install unixodbc-dev
sudo apt install python3-dev
pip3 install --user pyodbc

I just didn't use --user because of ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv.

@kaarthik108
Copy link

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.

I solved it by using this command and then install pyodbc

! apt install unixodbc-dev -y

@iammathh
Copy link

Install pyodbc on Centos / RHEL

Why PyODBC is needed?

To connect to any Database via Python. (There are specific drivers available for each database, pyodbc serves as a common library)

These are must have libraries for any development work, so its better to have them installed as part of any CentOS / RHEL setup.

$ sudo yum install unixodbc-dev
$ sudo yum install unixODBC unixODBC-devel
$ sudo yum install epel-release$ sudo yum install gcc-c++

These are specific to Python ODBC.
Before using pip3, make sure you have pip installed.

$ pip3 --version
$ sudo yum install python3-devel
$ sudo pip3 install pyodbc

The installation can be tested as follows

$ python3

>>> import pyodbc

If no errors are thrown, then your installation is perfect.

@Paulo-Lopes-Estevao
Copy link

Ubuntu 20.04
python3.8

sudo apt-get install python3-dev
sudo apt-get install unixodbc-dev
pip3 install pyodbc

@v-chojas
Copy link
Contributor

There is no point in bumping this issue - please read the documentation: https://github.com/mkleehammer/pyodbc/wiki/Install

@klentabistado
Copy link

This worked for me:

sudo apt-get install python3.8-dev

worked for me

@Tonelock
Copy link

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.

Had the same problem running pyodbc via poetry . This helped me, Thanks!

@esundberg
Copy link

esundberg commented Apr 8, 2022

Fix for Ubuntu 20.04 running Python3.8

apt install build-essential libssl-dev libffi-dev unixodbc python3.8 python3.8-dev unixodbc-dev

@chaowu2009
Copy link

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.

this works. thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests