> For the complete documentation index, see [llms.txt](https://platform9.com/kb/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://platform9.com/kb/generic/solution/pf9-hostagent-failing-with-error-no-module-named-apt-pkg.md).

# pf9-hostagent Failing With Error "No module named 'apt\_pkg'"

## Problem

The host is disconnected from Management Plane and `pf9-hostagent` service is failing and `hostagent-daemon.log` shows error `No module named 'apt_pkg'`

{% tabs %}
{% tab title="hostagent-daemon.log" %}

```javascript
customlogger.py INFO - from pf9app.pf9_app_db import Pf9AppDb as AppDb, Pf9AgentDb
customlogger.py INFO -   File "/opt/pf9/hostagent/lib/python3.9/site-packages/pf9app/pf9_app_db.py", line 21, in <module>

customlogger.py INFO - import apt
customlogger.py INFO -   File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>

customlogger.py INFO - import apt_pkg
customlogger.py INFO - ModuleNotFoundError
customlogger.py INFO - :
customlogger.py INFO - No module named 'apt_pkg'
```

{% endtab %}
{% endtabs %}

## Environment

* pf9-hostagent
* Python3

## Cause

When a newer python version is installed the link will update to point to the newest python version, which leads to the error of `apt_pkg` module not being found.

## Resolution

* Make sure package `python3-apt` is installed on the host.
* Fix the python symblink:

{% tabs %}
{% tab title="command" %}

```javascript
# cd /usr/lib/python3/dist-packages
# ln -s apt_pkg.cpython-35m-x86_64-linux-gnu.so apt_pkg.so
# ln -s apt_inst.cpython-35m-x86_64-linux-gnu.so  apt_inst.so
```

{% endtab %}
{% endtabs %}

* Restart `pf9-hostagent` service:

{% tabs %}
{% tab title="command" %}

```javascript
# systemctl restart pf9-hostagent
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://platform9.com/kb/generic/solution/pf9-hostagent-failing-with-error-no-module-named-apt-pkg.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
