8

Solution provided below:

Started getting errors when building pygdal on Ubuntu 20.04:

# Command
python3 -m pip install --no-cache-dir pygdal==3.0.4.*

produces the following output

Collecting pygdal==3.0.4.*
  Downloading pygdal-3.0.4.6.tar.gz (458 kB)
     |████████████████████████████████| 458 kB 3.7 MB/s 
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-we7e68ge/pygdal/setup.py'"'"'; __file__='"'"'/tmp/pip-install-we7e68ge/pygdal/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-we7e68ge/pygdal/pip-egg-info
         cwd: /tmp/pip-install-we7e68ge/pygdal/
    Complete output (5 lines):
    /usr/lib/python3.8/distutils/dist.py:274: UserWarning: Unknown distribution option: 'use_2to3_fixers'
      warnings.warn(msg)
    /usr/lib/python3.8/distutils/dist.py:274: UserWarning: Unknown distribution option: 'use_2to3_exclude_fixers'
      warnings.warn(msg)
    error in pygdal setup command: use_2to3 is invalid.
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

The steps to reproduce the error are:

# Commands to run inside of running Ubuntu 20.04 docker instance
apt update
# install python3.8 and link python3 to this version - these next 2 steps may not be needed for your scenario
apt install -y python3.8
ln -s /usr/bin/python3.8 /usr/bin/python3
# done installing python3.8
apt install -y python3-pip
apt-get install -y python3-gdal gdal-bin libgdal-dev gcc g++ python3.8-dev git
python3 -m pip install --upgrade --no-cache-dir setuptools==58.0.4
python3 -m pip install --upgrade --no-cache-dir numpy wheel requests
python3 -m pip install --no-cache-dir pygdal==3.0.4.*

The solution is to install an older version of setuptools. Specifying version 58.0.2 and earlier resulted in a successful build. I only went back to 58.0.0 for this issue, but this is the first time I've seen this issue so earlier versions should work as well.

# Replace the above installation of setuptools with the following
python3 -m pip install --upgrade --no-cache-dir setuptools==58.0.2
ChrisSc
  • 276
  • 2
  • 9
  • The GitHub issue for this can be found at https://github.com/pypa/setuptools/issues/2781 – ChrisSc Sep 09 '21 at 18:54
  • We're seeing this too, all of a sudden. Carefully looking at our build infra to see what changed but nothing has popped out at me yet after a careful look. – Ari Gesher Sep 10 '21 at 03:07
  • Suggestion, @chrissc: add your answer (from the body of the question) as an answer to make it easier to parse. Thanks for tracking this down, you saved our bacon. – Ari Gesher Sep 10 '21 at 03:36

3 Answers3

14

For installing GDAL version 3.0.4. In my case, I've downgrading the setuptools from 58.2.0 to 57.5.0 version worked. Using the command:

pip3 install setuptools==57.5.0
Sarah Abderemane
  • 596
  • 5
  • 14
Ratan gupta
  • 159
  • 2
  • This worked for me for GDAL 3.0.0. – Dave Nov 12 '21 at 18:37
  • 1
    For me, this happened when installing using Poetry, since Poetry versions `<1.2` depend on a `setuptools` greater than `57.5.0`, breaking GDAL build (version 3.2.2 in my case). Doing this `pip install` before the `poetry install` works and fixes this error. – Pablo Alexis Domínguez Grau Mar 27 '22 at 02:28
  • If you still have problems, try to also use an old pip, like `pip install pip==20.0.2` – Manel Clos Jul 14 '23 at 03:55
8

Replace the above installation of setuptools with the following

python3 -m pip install --upgrade --no-cache-dir setuptools==58.0.2

depending upon which version of pygdal you are using, you may need to use an earlier version of setuptools

ChrisSc
  • 276
  • 2
  • 9
1

What helped me was to install the python GDAL version which is the same as the distribution GDAL. for Ubuntu:

gadi@gadi:$ dpkg-query --list |grep gdal
ii  gdal-bin                                      3.4.1+dfsg-1build4                      amd64        Geospatial Data Abstraction Library 

and then

pip install GDAL==3.4.1
Gadi
  • 76
  • 5