mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.89k stars 562 forks source link

Failed building wheel for pyodbc #1076

Closed manalkhalifa closed 1 year ago

manalkhalifa commented 2 years ago

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:

i try to install pyodbc via pip pip install pyodbc and i got this error


Looking in indexes: https://analytics-rspm.hosting.corp/Pypi/latest/simple
Collecting pyodbc
  Downloading https://analytics-rspm.hosting.corp/Pypi/latest/packages/9be5f0c3590655e1968488410fe3528bb8023d527e7ccec1f663d64245071a6b/pyodbc-4.0.32.tar.gz (280 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 280.0/280.0 kB 2.0 MB/s eta 0:00:00a 0:00:01
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: pyodbc
  Building wheel for pyodbc (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [14 lines of output]
      running bdist_wheel
      running build
      running build_ext
      building 'pyodbc' extension
      creating build
      creating build/temp.linux-x86_64-cpython-38
      creating build/temp.linux-x86_64-cpython-38/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 -I/opt/rh/rh-python38/root/usr/include -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 -I/opt/rh/rh-python38/root/usr/include -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.32 -I/opt/pyvenv/py38-venv/include -I/opt/rh/rh-python38/root/usr/include/python3.8 -c src/buffer.cpp -o build/temp.linux-x86_64-cpython-38/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 '/usr/bin/gcc' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: 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
  error: subprocess-exited-with-error

  × Running setup.py install for pyodbc did not run successfully.
  │ exit code: 1
  ╰─> [16 lines of output]
      running install
      /opt/pyvenv/py38-venv/lib64/python3.8/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_ext
      building 'pyodbc' extension
      creating build
      creating build/temp.linux-x86_64-cpython-38
      creating build/temp.linux-x86_64-cpython-38/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 -I/opt/rh/rh-python38/root/usr/include -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 -I/opt/rh/rh-python38/root/usr/include -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.32 -I/opt/pyvenv/py38-venv/include -I/opt/rh/rh-python38/root/usr/include/python3.8 -c src/buffer.cpp -o build/temp.linux-x86_64-cpython-38/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 '/usr/bin/gcc' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> pyodbc

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
Note: you may need to restart the kernel to use updated packages.

```i tried to install this dependencies but  doesnt slove it : 
unixODBC
unixodbc-dev
gcc-c++
crash5 commented 2 years ago

src/pyodbc.h:45:20: fatal error: Python.h: No such file or directory do you have python-dev or similar package installed?

manalkhalifa commented 2 years ago

Yes. I already installed python3-devel but still doesnt work

manalkhalifa commented 2 years ago

I see that python3-devel support all python3. X Version. But hoe we can find where python3-devel include in the python36 virtual env to do the same with python38

gregholst commented 2 years ago

Had the same issue, but with Python 3.9 and running on Ubuntu 20.04. Maybe installing unixodbc-dev:

sudo apt install unixodbc-dev

helps for you as well. See here: https://stackoverflow.com/questions/71383153/pyodbc-legacy-install-failure-in-ubuntu-python-3-9/72935800#72935800

mkleehammer commented 2 years ago

I don't know why the include directory from python-devel is not being used yet, but you may not need it. Version 4.0.34 was released yesterday with prebuild binary wheels for Linux. If you install again today, it might work just fine.

mkleehammer commented 1 year ago

Thanks to an amazing job by @keitherskine, new releases build official wheels now. There is an official 4.0.35 wheel available.

maazsabahuddin commented 1 year ago

pull official base image

I have used python:3.11-alpine

install dependencies (g++ is required for pyodbc)

RUN apk update && apk add postgresql-dev gcc g++ unixodbc-dev python3-dev curl bash sudo

The above Dockerfile works for me.

taowan1 commented 1 year ago

I'm using python3.8 same issue is resolved on my side by below command: sudo apt install python3.8-dev