Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named 'yaml'

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?

like image 329
Neeraj Avatar asked Jun 15 '18 02:06

Neeraj


People also ask

How do I fix ImportError No module named Yaml?

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.

Can not find module Yaml?

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.

How do I read a YAML file in Python?

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.


2 Answers

pip install pyyaml 

This should serve the purpose

like image 110
illusionx Avatar answered Sep 23 '22 03:09

illusionx


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

like image 32
Waket Zheng Avatar answered Sep 22 '22 03:09

Waket Zheng