How to fix: No module named apt_pkg

This is what I get in my mail after cron-daily fails to upgrade:

1
2
3
4
5
6
7
/etc/cron.daily/apt:
Traceback (most recent call last):
  File "/usr/bin/unattended-upgrade", line 55, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ImportError: No module named 'apt_pkg'

This can happen if you use python3.5 but have python-apt for 3.4.
Here is how to fix this apt pkg thing:

1
2
3
4
5
apt-get install python3-apt --reinstall

cd /usr/lib/python3/dist-packages
ln -s apt_pkg.cpython-{34m,35m}-x86_64-linux-gnu.so
ln -s apt_inst.cpython-{34m,35m}-x86_64-linux-gnu.so

{34m,35m} - which link to which. If you use 3.6 but the module is 3.5 then do {3.5m,3.6m} etc

Edit Report
Pub: 18 Jul 2018 10:05 UTC
Edit: 07 Aug 2018 17:13 UTC
Views: 1503