module 'yaml' has no attribute 'FullLoader'

Python

Python Problem Overview


I am seeing the following error:

 Traceback (most recent call last):
  File "generateLDA.py", line 14, in <module>
    config = yaml.load(fp, Loader = yaml.FullLoader)
AttributeError: module 'yaml' has no attribute 'FullLoader'

Python Solutions


Solution 1 - Python

The FullLoader class is only available in PyYAML 5.1 and later. Version 5.1 was released on March 13, 2019 and has probably not filtered down to many distributions yet.

You can check the version of PyYAML by inspecting yaml.__version__:

Python 2.7.15 (default, Oct 15 2018, 15:24:06) 
[GCC 8.1.1 20180712 (Red Hat 8.1.1-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import yaml
>>> yaml.__version__
'3.13'

If you are managing packages with pip, you can upgrade to the current release by running:

pip install -U PyYAML

Solution 2 - Python

In case someone wants to use older version of yaml(3.1)

import yaml
with open('filename.yaml') as parameters:
  my_dict = yaml.safe_load(parameters)

I stumbled upon it while using rospy to run my packages.

Solution 3 - Python

pip install --ignore-installed PyYAML

Solution 4 - Python

sudo su
pip install --ignore-installed PyYAML -r requirements.txt

It worked perfectly for fail2ban-geo-exporter

Took hours to figure it out, now it runs under root & systemd

Solution 5 - Python

pip3 install -U PyYAML

worked for me on Linux machine.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionB Srinivas MVGR ECEView Question on Stackoverflow
Solution 1 - PythonlarsksView Answer on Stackoverflow
Solution 2 - PythonBhargav DandamudiView Answer on Stackoverflow
Solution 3 - PythonhorhshubhamView Answer on Stackoverflow
Solution 4 - Pythonuser16465983View Answer on Stackoverflow
Solution 5 - Pythonuser3855082View Answer on Stackoverflow