添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
胡子拉碴的拐杖  ·  数据值·  5 小时前    · 
多情的长颈鹿  ·  python ...·  5 小时前    · 
坚韧的竹笋  ·  gold-miner/TODO/python ...·  5 小时前    · 
爱健身的灭火器  ·  Error: count(): ...·  3 月前    · 
乐观的针织衫  ·  org.apache.commons.lan ...·  6 月前    · 
千杯不醉的核桃  ·  中心成果 | ...·  9 月前    · 

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 pip install pyodbc failing: error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 wondernath opened this issue Aug 31, 2017 · 39 comments

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
  • 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/

    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.

    v-chojas, isvaldo, quetzaluz, henrytxz, obchap, ozone227, darksinge, mk123, andersonberg, azahradka, and 285 more reacted with thumbs up emoji rifatdinc, Vieufoux, FofiHdeza, angel-ubs, ganeshbhatms, nayanex, w1pereira, hjb0, and JagpreetGrewal reacted with laugh emoji santosgabriel, fenchu, thsunamy, pckben, skipp, PGrothaus, DoloMike, iamsaurabhc, vuonghv, JarkoDubbeldam, and 38 more reacted with hooray emoji tobecon, iamsaurabhc, maikcatrinque, dasturchiuz, keipa, heymanshudeepSingh, rails-to-cosmos, cr4zyd3v, cleverrocks, GregLeVieuxRat, and 54 more reacted with heart emoji cr4zyd3v, naserih, mwheeler-hdai, liquizz, thanos1983, jmwoloso, aashayamballi, parvathirajan, rifatdinc, Vieufoux, and 13 more reacted with rocket emoji All reactions

    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.

    ShayaTepper, mallmanj, PFadel, c0d3sling3r, spezifanta, TasseDeCafe, manisacharya, TheBestLL, dalalkrish, charlesashby, and 46 more reacted with thumbs up emoji pedro2555 reacted with laugh emoji pedro2555 reacted with hooray emoji bryanmullinbwp, azarudeena, ha2398, amarupak, ogord, pedro2555, schildner, fsackur, jfreeman2, maheensaleh, and 2 more reacted with heart emoji pedro2555 reacted with rocket emoji All reactions

    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
      martinmanzo, mohammadiahmad, spezifanta, ImadYIdrissi, lyriccoder, YeisonHunt, susankoju, nghongphuong94, XiaYuanxiang, gunarevuri37, and 18 more reacted with thumbs up emoji
      nikitagruia-dev, vincentchalamon, nghongphuong94, Harshada7, XiaYuanxiang, yviouswilliamous, ftmzhrsckldr, and WilsonKolana reacted with heart emoji
      alon1samuel, YeisonHunt, zacqed, nghongphuong94, yviouswilliamous, ftmzhrsckldr, WilsonKolana, and aghorbani57 reacted with rocket emoji
        All reactions
      LeonanCarvalho, chinasjok, MKGrizzly71, kirpheaice, NickFursa, BigCheeze45, juanesfonsecan, spezifanta, ankurgadgilwar, EkesiR, and 15 more reacted with thumbs up emoji
      TechLee2019, visakan4, and hasija reacted with thumbs down emoji
      LeonanCarvalho, kirpheaice, v-ken, mithunmanohar, and paulsuk1982 reacted with hooray emoji
      LeonanCarvalho, kirpheaice, juanesfonsecan, and v-ken reacted with heart emoji
      sergiomora03 reacted with rocket emoji
        All reactions
      luissamano, Reston, ja0nz, MihaiChelaru, mateoSerna, srbiotik, Dridou, arihantsoganijain, shankararul-kering, helloitu, and 18 more reacted with thumbs up emoji
      bryanmullinbwp, arihantsoganijain, helloitu, zy964c, bj4rtmar, karlkaebnick, carsongregory, leandrochl, danielfsilva88, and qgerome reacted with heart emoji
      alon1samuel, helloitu, zy964c, karlkaebnick, yjiang-statestitle, and yusufaytas reacted with rocket emoji
        All reactions
              

    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!

    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.

    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.

    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?

    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'

    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.

    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

    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

    When I am installing pyodbc using command propmpt for sql server it returns following error.

    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.

    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

    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.

    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!

    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