Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDAL Virtualenv Python 3.6 Installation

I am having a brutal time getting gdal installed. I have a fresh install of Ubuntu Mint with a virtualenv Python 3.6 environment that I am trying to get GDAL installed on. After working through all the dependency requirements I now get the following error after running pip install gdal:

Collecting gdal
  Using cached https://files.pythonhosted.org/packages/99/31/2e05c1be3196126fa04028aed51489f40ceea77e8361a80bc8b00fc463db/GDAL-2.3.1.tar.gz
Building wheels for collected packages: gdal
  Running setup.py bdist_wheel for gdal ... error
  Complete output from command /home/mnewman/pyenvs/py36/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-sxbz7tcv/gdal/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/tmp00t__5p7pip-wheel- --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.6
  copying gdal.py -> build/lib.linux-x86_64-3.6
  copying ogr.py -> build/lib.linux-x86_64-3.6
  copying osr.py -> build/lib.linux-x86_64-3.6
  copying gdalconst.py -> build/lib.linux-x86_64-3.6
  copying gnm.py -> build/lib.linux-x86_64-3.6
  copying gdalnumeric.py -> build/lib.linux-x86_64-3.6
  creating build/lib.linux-x86_64-3.6/osgeo
  copying osgeo/gdal_array.py -> build/lib.linux-x86_64-3.6/osgeo
  copying osgeo/gdalconst.py -> build/lib.linux-x86_64-3.6/osgeo
  copying osgeo/__init__.py -> build/lib.linux-x86_64-3.6/osgeo
  copying osgeo/gnm.py -> build/lib.linux-x86_64-3.6/osgeo
  copying osgeo/osr.py -> build/lib.linux-x86_64-3.6/osgeo
  copying osgeo/ogr.py -> build/lib.linux-x86_64-3.6/osgeo
  copying osgeo/gdalnumeric.py -> build/lib.linux-x86_64-3.6/osgeo
  copying osgeo/gdal.py -> build/lib.linux-x86_64-3.6/osgeo
  Fixing build/lib.linux-x86_64-3.6/gdal.py build/lib.linux-x86_64-3.6/ogr.py build/lib.linux-x86_64-3.6/osr.py build/lib.linux-x86_64-3.6/gdalconst.py build/lib.linux-x86_64-3.6/gnm.py build/lib.linux-x86_64-3.6/gdalnumeric.py build/lib.linux-x86_64-3.6/osgeo/gdal_array.py build/lib.linux-x86_64-3.6/osgeo/gdalconst.py build/lib.linux-x86_64-3.6/osgeo/__init__.py build/lib.linux-x86_64-3.6/osgeo/gnm.py build/lib.linux-x86_64-3.6/osgeo/osr.py build/lib.linux-x86_64-3.6/osgeo/ogr.py build/lib.linux-x86_64-3.6/osgeo/gdalnumeric.py build/lib.linux-x86_64-3.6/osgeo/gdal.py
  Skipping optional fixer: ws_comma
  Fixing build/lib.linux-x86_64-3.6/gdal.py build/lib.linux-x86_64-3.6/ogr.py build/lib.linux-x86_64-3.6/osr.py build/lib.linux-x86_64-3.6/gdalconst.py build/lib.linux-x86_64-3.6/gnm.py build/lib.linux-x86_64-3.6/gdalnumeric.py build/lib.linux-x86_64-3.6/osgeo/gdal_array.py build/lib.linux-x86_64-3.6/osgeo/gdalconst.py build/lib.linux-x86_64-3.6/osgeo/__init__.py build/lib.linux-x86_64-3.6/osgeo/gnm.py build/lib.linux-x86_64-3.6/osgeo/osr.py build/lib.linux-x86_64-3.6/osgeo/ogr.py build/lib.linux-x86_64-3.6/osgeo/gdalnumeric.py build/lib.linux-x86_64-3.6/osgeo/gdal.py
  Skipping optional fixer: ws_comma
  running build_ext
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-EKG1lX/python3.6-3.6.5=. -specs=/usr/share/dpkg/no-pie-compile.specs -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/mnewman/pyenvs/py36/include -I/usr/include/python3.6m -I/home/mnewman/pyenvs/py36/lib/python3.6/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.6
  creating build/temp.linux-x86_64-3.6/extensions
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-EKG1lX/python3.6-3.6.5=. -specs=/usr/share/dpkg/no-pie-compile.specs -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/mnewman/pyenvs/py36/include -I/usr/include/python3.6m -I/home/mnewman/pyenvs/py36/lib/python3.6/site-packages/numpy/core/include -I/usr/include -c extensions/gdal_wrap.cpp -o build/temp.linux-x86_64-3.6/extensions/gdal_wrap.o -I/usr/include/gdal
  cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
  extensions/gdal_wrap.cpp: In function ‘retStringAndCPLFree* wrapper_VSIGetSignedURL(const char*, char**)’:
  extensions/gdal_wrap.cpp:4067:12: error: ‘VSIGetSignedURL’ was not declared in this scope
       return VSIGetSignedURL( utf8_path, options );
              ^~~~~~~~~~~~~~~
  extensions/gdal_wrap.cpp:4067:12: note: suggested alternative: ‘VSIRewindL’
       return VSIGetSignedURL( utf8_path, options );
              ^~~~~~~~~~~~~~~
              VSIRewindL
  extensions/gdal_wrap.cpp: In function ‘PyObject* _wrap_GetErrorCounter(PyObject*, PyObject*)’:
  extensions/gdal_wrap.cpp:7465:14: error: ‘CPLGetErrorCounter’ was not declared in this scope
       result = CPLGetErrorCounter();
                ^~~~~~~~~~~~~~~~~~
  extensions/gdal_wrap.cpp:7465:14: note: suggested alternative: ‘_wrap_GetErrorCounter’
       result = CPLGetErrorCounter();
                ^~~~~~~~~~~~~~~~~~
                _wrap_GetErrorCounter
  extensions/gdal_wrap.cpp: In function ‘PyObject* _wrap_MkdirRecursive(PyObject*, PyObject*)’:
  extensions/gdal_wrap.cpp:8553:16: error: ‘VSIMkdirRecursive’ was not declared in this scope
         result = VSIMkdirRecursive((char const *)arg1,arg2);
                  ^~~~~~~~~~~~~~~~~
  extensions/gdal_wrap.cpp:8553:16: note: suggested alternative: ‘VSIReadDirRecursive’
         result = VSIMkdirRecursive((char const *)arg1,arg2);
                  ^~~~~~~~~~~~~~~~~
                  VSIReadDirRecursive
  extensions/gdal_wrap.cpp: In function ‘PyObject* _wrap_RmdirRecursive(PyObject*, PyObject*)’:
  extensions/gdal_wrap.cpp:8623:16: error: ‘VSIRmdirRecursive’ was not declared in this scope
         result = VSIRmdirRecursive((char const *)arg1);
                  ^~~~~~~~~~~~~~~~~
  extensions/gdal_wrap.cpp:8623:16: note: suggested alternative: ‘VSIReadDirRecursive’
         result = VSIRmdirRecursive((char const *)arg1);
                  ^~~~~~~~~~~~~~~~~
                  VSIReadDirRecursive
  extensions/gdal_wrap.cpp: In function ‘PyObject* _wrap_GetActualURL(PyObject*, PyObject*)’:
  extensions/gdal_wrap.cpp:8788:24: error: ‘VSIGetActualURL’ was not declared in this scope
         result = (char *)VSIGetActualURL((char const *)arg1);
                          ^~~~~~~~~~~~~~~
  extensions/gdal_wrap.cpp:8788:24: note: suggested alternative: ‘_wrap_GetActualURL’
         result = (char *)VSIGetActualURL((char const *)arg1);
                          ^~~~~~~~~~~~~~~
                          _wrap_GetActualURL
  extensions/gdal_wrap.cpp: In function ‘PyObject* _wrap_GetFileSystemsPrefixes(PyObject*, PyObject*)’:
  extensions/gdal_wrap.cpp:8962:25: error: ‘VSIGetFileSystemsPrefixes’ was not declared in this scope
         result = (char **)VSIGetFileSystemsPrefixes();
                           ^~~~~~~~~~~~~~~~~~~~~~~~~
  extensions/gdal_wrap.cpp:8962:25: note: suggested alternative: ‘_wrap_GetFileSystemsPrefixes’
         result = (char **)VSIGetFileSystemsPrefixes();
                           ^~~~~~~~~~~~~~~~~~~~~~~~~
                           _wrap_GetFileSystemsPrefixes
  extensions/gdal_wrap.cpp: In function ‘PyObject* _wrap_GetFileSystemOptions(PyObject*, PyObject*)’:
  extensions/gdal_wrap.cpp:9026:24: error: ‘VSIGetFileSystemOptions’ was not declared in this scope
         result = (char *)VSIGetFileSystemOptions((char const *)arg1);
                          ^~~~~~~~~~~~~~~~~~~~~~~
  extensions/gdal_wrap.cpp:9026:24: note: suggested alternative: ‘_wrap_GetFileSystemOptions’
         result = (char *)VSIGetFileSystemOptions((char const *)arg1);
                          ^~~~~~~~~~~~~~~~~~~~~~~
                          _wrap_GetFileSystemOptions
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for gdal
  Running setup.py clean for gdal
Failed to build gdal

Not sure what I am missing here, I have installed all the libraries and -dev versions.

like image 659
Zexelon Avatar asked Aug 20 '18 15:08

Zexelon


People also ask

What version of Python does GDAL use?

Currently, GDAL Python code itself is compatible with Python 2 and Python 3.

Can you install GDAL with PIP?

gdal-utils: is the GDAL Python Utilities distribution. This is what you install. Its home page is https://pypi.org/project/gdal-utils/ . Install with pip install gdal-utils .


Video Answer


1 Answers

I solved it via:

install the newest version of gdal-bin and libgdal-dev:

sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
sudo apt update
sudo apt upgrade
sudo apt install gdal-bin libgdal-dev

My gdal version was 2.2.3, so maybe specifically install that one if this does not work.

install using pip3:

pip install --global-option=build_ext --global-option="-I/usr/include/gdal" GDAL==`gdal-config --version`
like image 92
Herbert Avatar answered Oct 17 '22 20:10

Herbert