Issue with Hestia Update Cron Job: `ModuleNotFoundError: No module named 'apt_pkg'`

Hello everyone,

I’m currently experiencing an issue with my Hestia control panel on an Ubuntu server. Every time the cron job runs to update Hestia (sudo /usr/local/hestia/bin/v-update-sys-hestia-all), I receive the following error message via email:

Traceback (most recent call last):
  File "/usr/lib/cnf-update-db", line 3, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db >/dev/null; fi'
E: Sub-process returned an error code
Traceback (most recent call last):
  File "/usr/lib/cnf-update-db", line 3, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

I have tried the following steps to resolve the issue:

  1. Confirmed python3-apt is installed and up-to-date: The package python3-apt is installed, and it’s already the newest version (2.4.0ubuntu3).

  2. System Update and Upgrade: I ran sudo apt update && sudo apt upgrade to ensure all packages are up-to-date.

  3. Reinstalled python3-apt: I removed and reinstalled the python3-apt package using:

    sudo apt remove --purge python3-apt
    sudo apt install python3-apt
    
  4. Checked Python Path: Verified the Python path to ensure it includes the necessary directories for apt_pkg.

  5. Ran dpkg --configure -a: I attempted to fix broken package configurations.

  6. Reinstalled command-not-found package: Tried reinstalling the package that includes /usr/lib/cnf-update-db.

Despite these efforts, the error persists. I suspect there might be a configuration issue with Hestia or the environment variables that are causing this problem, but I’m not sure how to proceed.

Has anyone faced a similar issue or could provide any suggestions to resolve this? Any help would be greatly appreciated!

Thank you in advance.

Hi @MesterPerfect,

That error doesn’t seem related to Hestia. Did you install a different python version than the default provided by your distribution?

Show the output of these commands:

python3 -V
ls -l /usr/lib/python3/dist-packages/ | grep apt_pkg
1 Like

Hi,

Thank you for the response.

Yes, I did update Python from the default version (Python 3.10) to a newer version (Python 3.12). It seems that the apt_pkg module is only available for Python 3.10, as indicated by the output of the commands:

$ python3 -V
Python 3.12.5

$ ls -l /usr/lib/python3/dist-packages/ | grep apt_pkg
-rw-r--r-- 1 root root 347096 Feb 13  2024 apt_pkg.cpython-310-x86_64-linux-gnu.so
drwxr-xr-x 2 root root   4096 Aug 31 05:03 apt_pkg-stubs

It appears that the apt_pkg module has not been updated or linked for Python 3.12. Could this be causing the issue, and what would be the best way to resolve this? Should I revert to Python 3.10, or is there a way to make apt_pkg compatible with Python 3.12?

Thanks for your help!

Try this:

cd /usr/lib/python3/dist-packages/
ln -s apt_pkg.cpython-310-x86_64-linux-gnu.so apt_pkg.so
2 Likes

I used the following commands:

cd /usr/lib/python3/dist-packages/
ln -s apt_pkg.cpython-310-x86_64-linux-gnu.so apt_pkg.so

Then I ran the command:

sudo /usr/local/hestia/bin/v-update-sys-hestia-all

It executed successfully.

Thank you!

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.