dpkg: error processing package qgis-providers (--configure):

HI got this will installing anything.

(base) mi@adib:~$ sudo apt install gnupg software-properties-common
[sudo] password for mi: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
gnupg is already the newest version (2.2.19-3ubuntu2).
software-properties-common is already the newest version (0.98.9.3).
The following packages were automatically installed and are no longer required:
  libgsl23 libgslcblas0 libjs-leaflet libqgis-3d3.16.2 libqgis-analysis3.16.2
  libqgis-app3.16.2 libqgis-app3.16.3 libqgis-core3.16.2 libqgis-gui3.16.2
  libqgis-native3.16.2 libqgis-server3.16.2 libqgispython3.16.2 libqt5charts5
  qgis-common qml-module-qtcharts r-cran-mathjaxr
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.
3 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up qgis-providers (1:3.16.3+32focal) ...
    - 'VirtualXPath'    [XML Path Language - XPath]
    - 'VirtualXPath'    [XML Path Language - XPath]
    - 'VirtualXPath'    [XML Path Language - XPath]
free(): invalid pointer
Aborted (core dumped)
dpkg: error processing package qgis-providers (--configure):
 installed qgis-providers package post-installation script subprocess returned e
rror exit status 134
dpkg: dependency problems prevent configuration of python3-qgis:
 python3-qgis depends on qgis-providers (= 1:3.16.3+32focal); however:
  Package qgis-providers is not configured yet.

dpkg: error processing package python3-qgis (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of python-qgis:
 python-qgis depends on python3-qgis; however:
  Package python3-qgis is not configured yet.

dpkg: error processing package python-qgis (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup erro
r from a previous failure.
                          No apport report written because the error message ind
icates its a followup error from a previous failure.
                                                    Errors were encountered whil
e processing:
 qgis-providers
 python3-qgis
 python-qgis
E: Sub-process /usr/bin/dpkg returned an error code (1)

I ran into the same issue on updating QGIS.

There is already a bug report in Github for it.

You have to remove older versions of libproj manually, as described in the answers to the bug report:

 # remove offending lib while keeping package dependency installed (wow, ugly):
 rm -f /lib/x86_64-linux-gnu/libproj.so.15
 ln -s /lib/x86_64-linux-gnu/libproj.so.19 /lib/x86_64-linux-gnu/libproj.so.15

Folder names might be different for you, so look them up manually.

See also this similar GisStackExchange topic.


To fix this on my side, I had to uninstall libproj* manually

sudo apt remove libproj15 libproj-dev libproj19