Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

module 'yaml' has no attribute 'FullLoader'

Tags:

python

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'
like image 495
B Srinivas MVGR ECE Avatar asked Apr 06 '19 16:04

B Srinivas MVGR ECE


4 Answers

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
like image 53
larsks Avatar answered Oct 23 '22 17:10

larsks


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.

like image 30
Bhargav Dandamudi Avatar answered Oct 23 '22 16:10

Bhargav Dandamudi


pip install --ignore-installed PyYAML

like image 8
horhshubham Avatar answered Oct 23 '22 16:10

horhshubham


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

like image 1
user16465983 Avatar answered Oct 23 '22 18:10

user16465983