'Error Updating GDAL using pip (python3) on Ubuntu 20.04 LTS

I have a Linux Server (Ubuntu 20.04 LTS) and I am trying to update GDAL. All below has been used to update packages:

/usr/bin/python3 -m pip install --upgrade pip
/usr/bin/python3 -m pip install --upgrade wheel
/usr/bin/python3 -m pip install --upgrade setuptools

Then, to check GDAL version:

gdal2tiles.py --version
GDAL 3.0.4, released 2020/01/28
Traceback (most recent call last):
  File "/usr/bin/gdal2tiles.py", line 2915, in <module>
    main()
  File "/usr/bin/gdal2tiles.py", line 2905, in main
    input_file, output_folder, options = process_args(argv[1:])
TypeError: 'NoneType' object is not subscriptable

I am not sure why those errors just when showing the version.

Anyhow, I use the following command to try to update GDAL and I get error about building the wheel:

/usr/bin/python3 -m pip install --upgrade GDAL

Errors:

  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.
╰─> GDAL

      extensions/gdal_wrap.cpp:5573:13: warning: ‘CheckNumericDataType’ defined but not used [-Wunused-variable]
       5573 | static bool CheckNumericDataType(GDALExtendedDataTypeHS* dt)
            |             ^~~~~~~~~~~~~~~~~~~~
      error: command '/usr/bin/x86_64-linux-gnu-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.
╰─> GDAL


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source