ImportError: No module named ‘anydbm’ on Debian Linux – Solution

Symptoms

When using apt-get suite tools on Debian Linux you may notice a error message similar to the one below:

Traceback (most recent call last):
  File "/usr/bin/apt-listchanges", line 29, in 
    import anydbm
ImportError: No module named 'anydbm'

The above error is likely caused by a change of a system wide python interpreter version from a default Python2 to Python3 version.

# python -V
Python 3.4.2

Solution

To fix this error change a default interpreter from /usr/bin/apt-listchanges to Python 2. First, check available python versions on your system:

# ls /usr/bin/python*
/usr/bin/python  /usr/bin/python2  /usr/bin/python2.7  /usr/bin/python3  /usr/bin/python3.4  /usr/bin/python3.4m  /usr/bin/python3m

Next, change a first line of /usr/bin/apt-listchanges script:

FROM:
#!/usr/bin/python
TO:
#!/usr/bin/python2.7

The actual python version depends on your Debian version installation.