ModuleNotFoundError: No module named 'ruamel'
Question:
I’m using a Kubernetes inventory builder script found here: https://github.com/kubernetes-sigs/kubespray/blob/master/contrib/inventory_builder/inventory.py
On line 36
, the ruamel YML library is imported using the code from ruamel.yaml import YAML
. This library can be found here: https://pypi.org/project/ruamel.yaml/
On my OSX device (Mojave 10.14.3
), if I run pip list
, I can clearly see the most up to date version of ruamel.yaml
:
If I run pip show ruamel.yaml
, I get the following output:
I’m running the script with this command: CONFIG_FILE=inventory/mycluster/hosts.ini python3 contrib/inventory_builder/inventory.py 10.0.0.1 10.0.0.2 10.0.0.4 10.0.0.5
Bizarrely, it returns the following error:
Traceback (most recent call last):
File "contrib/inventory_builder/inventory.py", line 36, in <module>
from ruamel.yaml import YAML
ModuleNotFoundError: No module named 'ruamel'
I have very little experience with Python, so don’t understand how this could be failing. Have I installed the library incorrectly or something? From the documentation on the ruamel.yml
project page, it looks like the script is calling the library as it should be.
Thanks in advance
Answers:
you’re using python 3 and want to use the package that is with python 2. Go to the directory where your python 3 is, navigate to Scripts and use the pip in there to install the needed library.
pip
is set to point to the Python 2 installation. To install the library under Python 3, do pip3 install ruamel.yml
.
In my case, I was installing this with pip3 install ruamel.yaml
, and it was puting the package in /usr/local/lib/python3.9/site-packages/
, but the python3
binary on the machine was pinned to Python 3.7, so trying to import that module was sending the ModuleNotFoundError
message.
What helped to fix this, was to install the module with python3 -m pip install ruamel.yaml
, running pip via the python3 binary makes sure it runs on the same version, in this case 3.7, and gets installed via the correct version number site-packages.
This helped me (adding version number to python):
CONFIG_FILE=inventory/mycluster/hosts.yaml python3.6 contrib/inventory_builder/inventory.py ${IPS[@]}
[python 3.10.x].
There is no package called ruamel.yaml
what worked is pip install ruamel-yaml
I’m using a Kubernetes inventory builder script found here: https://github.com/kubernetes-sigs/kubespray/blob/master/contrib/inventory_builder/inventory.py
On line 36
, the ruamel YML library is imported using the code from ruamel.yaml import YAML
. This library can be found here: https://pypi.org/project/ruamel.yaml/
On my OSX device (Mojave 10.14.3
), if I run pip list
, I can clearly see the most up to date version of ruamel.yaml
:
If I run pip show ruamel.yaml
, I get the following output:
I’m running the script with this command: CONFIG_FILE=inventory/mycluster/hosts.ini python3 contrib/inventory_builder/inventory.py 10.0.0.1 10.0.0.2 10.0.0.4 10.0.0.5
Bizarrely, it returns the following error:
Traceback (most recent call last):
File "contrib/inventory_builder/inventory.py", line 36, in <module>
from ruamel.yaml import YAML
ModuleNotFoundError: No module named 'ruamel'
I have very little experience with Python, so don’t understand how this could be failing. Have I installed the library incorrectly or something? From the documentation on the ruamel.yml
project page, it looks like the script is calling the library as it should be.
Thanks in advance
you’re using python 3 and want to use the package that is with python 2. Go to the directory where your python 3 is, navigate to Scripts and use the pip in there to install the needed library.
pip
is set to point to the Python 2 installation. To install the library under Python 3, do pip3 install ruamel.yml
.
In my case, I was installing this with pip3 install ruamel.yaml
, and it was puting the package in /usr/local/lib/python3.9/site-packages/
, but the python3
binary on the machine was pinned to Python 3.7, so trying to import that module was sending the ModuleNotFoundError
message.
What helped to fix this, was to install the module with python3 -m pip install ruamel.yaml
, running pip via the python3 binary makes sure it runs on the same version, in this case 3.7, and gets installed via the correct version number site-packages.
This helped me (adding version number to python):
CONFIG_FILE=inventory/mycluster/hosts.yaml python3.6 contrib/inventory_builder/inventory.py ${IPS[@]}
[python 3.10.x].
There is no package called ruamel.yaml
what worked is pip install ruamel-yaml