I have one script in which I am trying to execute
python3 env/common_config/add_imagepullsecret.py
But, I am getting the following error:
[root@kevin]# python3 env/common_config/add_imagepullsecret.py Traceback (most recent call last): File "env/common_config/add_imagepullsecret.py", line 4, in <module> import yaml ImportError: No module named 'yaml' [root@kevin]# pip3 install pyyaml Requirement already satisfied: pyyaml in /usr/lib64/python3.4/site-packages (3.12) [root@kevin]#
PyYAML is already installed in the machine:
[root@bhimsvm31 k8s]# pip3 install pyyaml Requirement already satisfied: pyyaml in /usr/lib64/python3.4/site-packages (3.12) [root@bhimsvm31 k8s]#
How can I get this script to import PyYAML?
To Solve ImportError: No module named 'yaml' Error To solve this error all you need to do is just install pyyaml using this command. pip install pyyaml. To Solve ImportError: No module named 'yaml' Error To solve this error all you need to do is just install pyyaml using this command. pip install pyyaml.
The Python "ModuleNotFoundError: No module named 'yaml'" occurs when we forget to install the pyyaml module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install pyyaml command.
We can read the YAML file using the PyYAML module's yaml. load() function. This function parse and converts a YAML object to a Python dictionary ( dict object). This process is known as Deserializing YAML into a Python.
pip install pyyaml
This should serve the purpose
Solution 1: install python 3.6(or use pyenv
to manage py version) and ln python3 to it
export $PYPATH=`which python3` wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz tar -Jxf Python-3.6.5.tar.xz cd Python-3.6.5/ ./configure && make && make altinstall rm $PYPATH ln -s `which python3.6` $PYPATH python3 -m pip install pyyaml python3 env/common_config/add_imagepullsecret.py
Solution 2: use virtualenv (or python -m venv
)
pip3 install virtualenv virtualenv --python=python3 venv source venv/bin/activate pip install pyyaml python env/common_config/add_imagepullsecret.py
Solution 3: use python-poetry
or pipenv
https://github.com/python-poetry/poetry
https://github.com/pypa/pipenv
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With