# Issue with Hestia Update Cron Job: \`ModuleNotFoundError: No module named 'apt\_pkg'\`

**URL:** <https://forum.hestiacp.com/t/issue-with-hestia-update-cron-job-modulenotfounderror-no-module-named-apt-pkg/15716>\
**Category:** Cron Jobs\
**Created:** [August 31, 2024, 2:08am UTC](https://forum.hestiacp.com/t/issue-with-hestia-update-cron-job-modulenotfounderror-no-module-named-apt-pkg/15716 "2024-08-31T02:08:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MesterPerfect](https://forum.hestiacp.com/user_avatar/forum.hestiacp.com/mesterperfect/32/3878_2.png) [@MesterPerfect](https://forum.hestiacp.com/u/MesterPerfect)\
**Post date:** [August 31, 2024, 2:08am UTC](https://forum.hestiacp.com/t/issue-with-hestia-update-cron-job-modulenotfounderror-no-module-named-apt-pkg/15716/1 "2024-08-31T02:08:47Z")

</div>

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:

```auto
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:

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.

---

<div class="post-metadata">

**Author:** ![sahsanu](https://forum.hestiacp.com/user_avatar/forum.hestiacp.com/sahsanu/32/9318_2.png) [@sahsanu](https://forum.hestiacp.com/u/sahsanu)\
**Post date:** [August 31, 2024, 6:43am UTC](https://forum.hestiacp.com/t/issue-with-hestia-update-cron-job-modulenotfounderror-no-module-named-apt-pkg/15716/2 "2024-08-31T06:43:52Z")

</div>

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:

```t
python3 -V
ls -l /usr/lib/python3/dist-packages/ | grep apt_pkg

```

---

<div class="post-metadata">

**Author:** ![MesterPerfect](https://forum.hestiacp.com/user_avatar/forum.hestiacp.com/mesterperfect/32/3878_2.png) [@MesterPerfect](https://forum.hestiacp.com/u/MesterPerfect)\
**Post date:** [August 31, 2024, 7:48am UTC](https://forum.hestiacp.com/t/issue-with-hestia-update-cron-job-modulenotfounderror-no-module-named-apt-pkg/15716/3 "2024-08-31T07:48:00Z")

</div>

> [@sahsanu](#):
>
> 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:
> 
> ```auto
> python3 -V
> ls -l /usr/lib/python3/dist-packages/ | grep apt_pkg
> 
> ```

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:

```auto
$ 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!

---

<div class="post-metadata">

**Author:** ![sahsanu](https://forum.hestiacp.com/user_avatar/forum.hestiacp.com/sahsanu/32/9318_2.png) [@sahsanu](https://forum.hestiacp.com/u/sahsanu)\
**Post date:** [August 31, 2024, 7:52am UTC](https://forum.hestiacp.com/t/issue-with-hestia-update-cron-job-modulenotfounderror-no-module-named-apt-pkg/15716/4 "2024-08-31T07:52:19Z")

</div>

Try this:

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

```

---

<div class="post-metadata">

**Author:** ![MesterPerfect](https://forum.hestiacp.com/user_avatar/forum.hestiacp.com/mesterperfect/32/3878_2.png) [@MesterPerfect](https://forum.hestiacp.com/u/MesterPerfect)\
**Post date:** [August 31, 2024, 7:59am UTC](https://forum.hestiacp.com/t/issue-with-hestia-update-cron-job-modulenotfounderror-no-module-named-apt-pkg/15716/5 "2024-08-31T07:59:03Z")

</div>

I used the following commands:

```bash
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:

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

```

It executed successfully.

Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://forum.hestiacp.com/uploads/default/original/1X/d9a5b68bf50ced83e880b56452e592b204761b19.png) [@system](https://forum.hestiacp.com/u/system)\
**Post date:** [September 30, 2024, 7:59am UTC](https://forum.hestiacp.com/t/issue-with-hestia-update-cron-job-modulenotfounderror-no-module-named-apt-pkg/15716/6 "2024-09-30T07:59:40Z")

</div>

Closed on September 30, 2024, 7:59am UTC

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