3

I am having trouble installing GDAL on Google Cloud Datalab. When I run:

!pip install gdal

I get the following error

Collecting gdal
Using cached GDAL-2.2.4.tar.gz
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info/GDAL.egg-info
writing pip-egg-info/GDAL.egg-info/PKG-INFO
writing top-level names to pip-egg-info/GDAL.egg-info/top_level.txt
writing dependency_links to pip-egg-info/GDAL.egg- 
info/dependency_links.txt
writing manifest file 'pip-egg-info/GDAL.egg-info/SOURCES.txt'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-build-umhRKK/gdal/setup.py", line 342, in <module>
    **extra )
  File "/usr/local/lib/python2.7/dist-packages/setuptools/__init__.py", 
  line 129, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in 
  run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/local/lib/python2.7/dist-packages/setuptools/command/egg_info.py", line 278, in run
    self.find_sources()
  File "/usr/local/lib/python2.7/dist-packages/setuptools/command/egg_info.py", line 293, in find_sources
    mm.run()
  File "/usr/local/lib/python2.7/dist-packages/setuptools/command/egg_info.py", line 524, in run
    self.add_defaults()
  File "/usr/local/lib/python2.7/dist-packages/setuptools/command/egg_info.py", line 560, in add_defaults
    sdist.add_defaults(self)
  File "/usr/local/lib/python2.7/dist-packages/setuptools/command/py36compat.py", line 36, in add_defaults
    self._add_defaults_ext()
  File "/usr/local/lib/python2.7/dist-packages/setuptools/command/py36compat.py", line 119, in _add_defaults_ext
    build_ext = self.get_finalized_command('build_ext')
  File "/usr/lib/python2.7/distutils/cmd.py", line 312, in get_finalized_command
    cmd_obj.ensure_finalized()
  File "/usr/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized
    self.finalize_options()
  File "/tmp/pip-build-umhRKK/gdal/setup.py", line 217, in finalize_options
    self.gdaldir = self.get_gdal_config('prefix')
  File "/tmp/pip-build-umhRKK/gdal/setup.py", line 191, in get_gdal_config
    return fetch_config(option)
  File "/tmp/pip-build-umhRKK/gdal/setup.py", line 144, in fetch_config
    raise gdal_config_error, e""")
  File "<string>", line 4, in <module>
__main__.gdal_config_error: [Errno 2] No such file or directory

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-umhRKK/gdal/

Same thing goes for :

!pip install gdal==2.2

or:

!pip install python-gdal

and a few other similar commands I have tried. The fix I discovered which was to update the setup-tools still gives me this problem after updating it. What is the problem?

Vaderstalk
  • 71
  • 5

1 Answers1

0

As per the Datalab documentation on how to add a Python library to Cloud Datalab, there are three approaches that you can follow to perform an installation of a third-party library in Cloud Datalab:

  1. Use !pip install lib-name. This has obviously not worked for you, even by applying some of the troubleshooting fixes you have found after looking around.
  2. Use the code in # Option 2 below to specify the command to run in the startup script of the Datalab instance, then proceed to restart it.
  3. Use your own Docker customized container, inherited from the Datalab Docker container. I know this option is the most complex, but it may be the most appropriate one for packages that require a more flexible customization, such as the gdal one you are having issues with.

Script to be used in option 2:

#Option 2
%%bash
echo "pip install lib-name" >> /content/datalab/.config/startup.sh
cat /content/datalab/.config/startup.sh
dsesto
  • 7,864
  • 2
  • 33
  • 50