# Failed to import the required Python library (librouteros)

**URL:** <https://forum.ansible.com/t/failed-to-import-the-required-python-library-librouteros/45677>\
**Category:** Get Help\
**Tags:** routeros\
**Created:** [April 14, 2026, 10:39am UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-librouteros/45677 "2026-04-14T10:39:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![oza4h07](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/oza4h07/32/1118_2.png) [@oza4h07](https://forum.ansible.com/u/oza4h07)\
**Post date:** [April 14, 2026, 10:39am UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-librouteros/45677/1 "2026-04-14T10:39:50Z")

</div>

Hello,  
I’m trying to use community.routeros.api for the first time. I’m using a venv in which I installed ansible. Hopefully, I correctly updated community.routeros to 3.19.0. in it.  
When running a simple task involving community.routeros.api module, I’ve got:

[ERROR]: Task failed: Module failed: Failed to import the required Python library (librouteros)

Any idea ?

Best regards

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [April 14, 2026, 2:31pm UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-librouteros/45677/2 "2026-04-14T14:31:51Z")

</div>

You need to install the Python `librouteros` library:

> **[Client Challenge](https://pypi.org/project/librouteros/)**

Into the `venv`:

> **[community.routeros.api module – Ansible module for RouterOS API — Ansible...](https://docs.ansible.com/projects/ansible/latest/collections/community/routeros/api_module.html#ansible-collections-community-routeros-api-module-requirements)**
>
> The below requirements are needed on the host that executes this module.

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [April 14, 2026, 7:01pm UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-librouteros/45677/3 "2026-04-14T19:01:24Z")

</div>

Also if you’re using a venv, you need to make sure that modules are actually using the venv. IIRC ansible-core doesn’t do that automatically when running modules against `localhost`.

---

<div class="post-metadata">

**Author:** ![oza4h07](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/oza4h07/32/1118_2.png) [@oza4h07](https://forum.ansible.com/u/oza4h07)\
**Post date:** [April 15, 2026, 9:11am UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-librouteros/45677/4 "2026-04-15T09:11:10Z")

</div>

I don’t know how I overlooked this librouteros requirement, thinking it belonged to community.routeros modules.  
I feel a bit stupid now.

Thank you very much for replying: after installing librouter with pip, it now works ok.

---

<div class="post-metadata">

**Author:** ![oza4h07](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/oza4h07/32/1118_2.png) [@oza4h07](https://forum.ansible.com/u/oza4h07)\
**Post date:** [April 15, 2026, 9:24am UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-librouteros/45677/5 "2026-04-15T09:24:27Z")

</div>

@felixfontein  
Thank you for replying. Can you elaborate a bit ?

Now I’m using ansible this way:

source /path/to/venv/bin/activate  
ansible localhost -i hosts.yml -m include\_role -a “name=whatever”

It seems to work.  
How can I check the behaviour you warned about ?

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [April 15, 2026, 3:40pm UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-librouteros/45677/6 "2026-04-15T15:40:38Z")

</div>

If you install the module requirements (`librouteros`) also in that venv, Ansible modules running for `localhost` might not find that library because they are not running in the context of the venv.

If you installed `librouteros` in the venv (and not globally), you can try to run one of the API based modules and see whether it works. If it complains about missing `librouteros`, you will have to point Ansible to the venv somehow. If it runs (and maybe complains about something else, depending on your use), everything’s fine 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [May 15, 2026, 3:41pm UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-librouteros/45677/7 "2026-05-15T15:41:13Z")

</div>

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