3

I'm trying to install GDAL through pip with same version in the system. But I'm getting this error:

(app_env) user@server:~$ pip install gdal==3.0.4
Collecting gdal==3.0.4
  Using cached GDAL-3.0.4.tar.gz (577 kB)
Building wheels for collected packages: gdal
  Building wheel for gdal (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/server/.virtualenvs/wetland_env/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-g163k7vu/gdal_049a3c8408cb41aea58042c9b1cf4637/setup.py'"'"'; __file__='"'"'/tmp/pip-install-g163k7vu/gdal_049a3c8408cb41aea58042c9b1cf4637/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-fek8joed
       cwd: /tmp/pip-install-g163k7vu/gdal_049a3c8408cb41aea58042c9b1cf4637/
  Complete output (36 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.8
  copying gdal.py -> build/lib.linux-x86_64-3.8
  copying ogr.py -> build/lib.linux-x86_64-3.8
  copying osr.py -> build/lib.linux-x86_64-3.8
  copying gdalconst.py -> build/lib.linux-x86_64-3.8
  copying gdalnumeric.py -> build/lib.linux-x86_64-3.8
  creating build/lib.linux-x86_64-3.8/osgeo
  copying osgeo/gnm.py -> build/lib.linux-x86_64-3.8/osgeo
  copying osgeo/gdal.py -> build/lib.linux-x86_64-3.8/osgeo
  copying osgeo/gdal_array.py -> build/lib.linux-x86_64-3.8/osgeo
  copying osgeo/gdalconst.py -> build/lib.linux-x86_64-3.8/osgeo
  copying osgeo/gdalnumeric.py -> build/lib.linux-x86_64-3.8/osgeo
  copying osgeo/ogr.py -> build/lib.linux-x86_64-3.8/osgeo
  copying osgeo/__init__.py -> build/lib.linux-x86_64-3.8/osgeo
  copying osgeo/osr.py -> build/lib.linux-x86_64-3.8/osgeo
  /home/server/.virtualenvs/wetland_env/lib/python3.8/site-packages/setuptools/lib2to3_ex.py:36: SetuptoolsDeprecationWarning: 2to3 support is deprecated. If the project still requires Python 2 support, please migrate to a single-codebase solution or employ an independent conversion process.
    warnings.warn(
  Fixing build/lib.linux-x86_64-3.8/gdal.py build/lib.linux-x86_64-3.8/ogr.py build/lib.linux-x86_64-3.8/osr.py build/lib.linux-x86_64-3.8/gdalconst.py build/lib.linux-x86_64-3.8/gdalnumeric.py build/lib.linux-x86_64-3.8/osgeo/gnm.py build/lib.linux-x86_64-3.8/osgeo/gdal.py build/lib.linux-x86_64-3.8/osgeo/gdal_array.py build/lib.linux-x86_64-3.8/osgeo/gdalconst.py build/lib.linux-x86_64-3.8/osgeo/gdalnumeric.py build/lib.linux-x86_64-3.8/osgeo/ogr.py build/lib.linux-x86_64-3.8/osgeo/__init__.py build/lib.linux-x86_64-3.8/osgeo/osr.py
  Skipping optional fixer: ws_comma
  Fixing build/lib.linux-x86_64-3.8/gdal.py build/lib.linux-x86_64-3.8/ogr.py build/lib.linux-x86_64-3.8/osr.py build/lib.linux-x86_64-3.8/gdalconst.py build/lib.linux-x86_64-3.8/gdalnumeric.py build/lib.linux-x86_64-3.8/osgeo/gnm.py build/lib.linux-x86_64-3.8/osgeo/gdal.py build/lib.linux-x86_64-3.8/osgeo/gdal_array.py build/lib.linux-x86_64-3.8/osgeo/gdalconst.py build/lib.linux-x86_64-3.8/osgeo/gdalnumeric.py build/lib.linux-x86_64-3.8/osgeo/ogr.py build/lib.linux-x86_64-3.8/osgeo/__init__.py build/lib.linux-x86_64-3.8/osgeo/osr.py
  Skipping optional fixer: ws_comma
  running build_ext
  x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/home/server/.virtualenvs/wetland_env/include -I/usr/include/python3.8 -I/home/server/.virtualenvs/wetland_env/lib/python3.8/site-packages/numpy/core/include -I/usr/include -c gdal_python_cxx11_test.cpp -o gdal_python_cxx11_test.o
  building 'osgeo._gdal' extension
  creating build/temp.linux-x86_64-3.8
  creating build/temp.linux-x86_64-3.8/extensions
  x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/home/server/.virtualenvs/wetland_env/include -I/usr/include/python3.8 -I/home/server/.virtualenvs/wetland_env/lib/python3.8/site-packages/numpy/core/include -I/usr/include -c extensions/gdal_wrap.cpp -o build/temp.linux-x86_64-3.8/extensions/gdal_wrap.o -I/usr/include/gdal
  extensions/gdal_wrap.cpp:173:11: fatal error: Python.h: No such file or directory
   # include <Python.h>
             ^~~~~~~~~~
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for gdal
  Running setup.py clean for gdal
Failed to build gdal
Installing collected packages: gdal
    Running setup.py install for gdal ... error
    ERROR: Command errored out with exit status 1:
     command: /home/server/.virtualenvs/wetland_env/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-g163k7vu/gdal_049a3c8408cb41aea58042c9b1cf4637/setup.py'"'"'; __file__='"'"'/tmp/pip-install-g163k7vu/gdal_049a3c8408cb41aea58042c9b1cf4637/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-21n68w5w/install-record.txt --single-version-externally-managed --compile --install-headers /home/server/.virtualenvs/wetland_env/include/site/python3.8/gdal
         cwd: /tmp/pip-install-g163k7vu/gdal_049a3c8408cb41aea58042c9b1cf4637/
    Complete output (36 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.8
    copying gdal.py -> build/lib.linux-x86_64-3.8
    copying ogr.py -> build/lib.linux-x86_64-3.8
    copying osr.py -> build/lib.linux-x86_64-3.8
    copying gdalconst.py -> build/lib.linux-x86_64-3.8
    copying gdalnumeric.py -> build/lib.linux-x86_64-3.8
    creating build/lib.linux-x86_64-3.8/osgeo
    copying osgeo/gnm.py -> build/lib.linux-x86_64-3.8/osgeo
    copying osgeo/gdal.py -> build/lib.linux-x86_64-3.8/osgeo
    copying osgeo/gdal_array.py -> build/lib.linux-x86_64-3.8/osgeo
    copying osgeo/gdalconst.py -> build/lib.linux-x86_64-3.8/osgeo
    copying osgeo/gdalnumeric.py -> build/lib.linux-x86_64-3.8/osgeo
    copying osgeo/ogr.py -> build/lib.linux-x86_64-3.8/osgeo
    copying osgeo/__init__.py -> build/lib.linux-x86_64-3.8/osgeo
    copying osgeo/osr.py -> build/lib.linux-x86_64-3.8/osgeo
    /home/server/.virtualenvs/wetland_env/lib/python3.8/site-packages/setuptools/lib2to3_ex.py:36: SetuptoolsDeprecationWarning: 2to3 support is deprecated. If the project still requires Python 2 support, please migrate to a single-codebase solution or employ an independent conversion process.
      warnings.warn(
    Fixing build/lib.linux-x86_64-3.8/gdal.py build/lib.linux-x86_64-3.8/ogr.py build/lib.linux-x86_64-3.8/osr.py build/lib.linux-x86_64-3.8/gdalconst.py build/lib.linux-x86_64-3.8/gdalnumeric.py build/lib.linux-x86_64-3.8/osgeo/gnm.py build/lib.linux-x86_64-3.8/osgeo/gdal.py build/lib.linux-x86_64-3.8/osgeo/gdal_array.py build/lib.linux-x86_64-3.8/osgeo/gdalconst.py build/lib.linux-x86_64-3.8/osgeo/gdalnumeric.py build/lib.linux-x86_64-3.8/osgeo/ogr.py build/lib.linux-x86_64-3.8/osgeo/__init__.py build/lib.linux-x86_64-3.8/osgeo/osr.py
    Skipping optional fixer: ws_comma
    Fixing build/lib.linux-x86_64-3.8/gdal.py build/lib.linux-x86_64-3.8/ogr.py build/lib.linux-x86_64-3.8/osr.py build/lib.linux-x86_64-3.8/gdalconst.py build/lib.linux-x86_64-3.8/gdalnumeric.py build/lib.linux-x86_64-3.8/osgeo/gnm.py build/lib.linux-x86_64-3.8/osgeo/gdal.py build/lib.linux-x86_64-3.8/osgeo/gdal_array.py build/lib.linux-x86_64-3.8/osgeo/gdalconst.py build/lib.linux-x86_64-3.8/osgeo/gdalnumeric.py build/lib.linux-x86_64-3.8/osgeo/ogr.py build/lib.linux-x86_64-3.8/osgeo/__init__.py build/lib.linux-x86_64-3.8/osgeo/osr.py
    Skipping optional fixer: ws_comma
    running build_ext
    x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/home/server/.virtualenvs/wetland_env/include -I/usr/include/python3.8 -I/home/server/.virtualenvs/wetland_env/lib/python3.8/site-packages/numpy/core/include -I/usr/include -c gdal_python_cxx11_test.cpp -o gdal_python_cxx11_test.o
    building 'osgeo._gdal' extension
    creating build/temp.linux-x86_64-3.8
    creating build/temp.linux-x86_64-3.8/extensions
    x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I../../port -I../../gcore -I../../alg -I../../ogr/ -I../../ogr/ogrsf_frmts -I../../gnm -I../../apps -I/home/server/.virtualenvs/wetland_env/include -I/usr/include/python3.8 -I/home/server/.virtualenvs/wetland_env/lib/python3.8/site-packages/numpy/core/include -I/usr/include -c extensions/gdal_wrap.cpp -o build/temp.linux-x86_64-3.8/extensions/gdal_wrap.o -I/usr/include/gdal
    extensions/gdal_wrap.cpp:173:11: fatal error: Python.h: No such file or directory
     # include <Python.h>
               ^~~~~~~~~~
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/server/.virtualenvs/wetland_env/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-g163k7vu/gdal_049a3c8408cb41aea58042c9b1cf4637/setup.py'"'"'; __file__='"'"'/tmp/pip-install-g163k7vu/gdal_049a3c8408cb41aea58042c9b1cf4637/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-21n68w5w/install-record.txt --single-version-externally-managed --compile --install-headers /home/server/.virtualenvs/wetland_env/include/site/python3.8/gdal Check the logs for full command output.
1

1 Answer 1

1

You probably need to install the Python development tools as you are missing the header file python.h:

for Python2 (deprecated): apt-get install python-dev

for Python3: apt-get install python3-dev

1
  • "python3-dev" already installed with latest version (3.6.7-1~18.04). postgresql postgis also showing error. CREATE EXTENSION postgis; ERROR: could not access file "$libdir/postgis-2.5": No such file or directory
    – Anju
    Commented Jul 9, 2021 at 7:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.