How do I solve these "unresolved attribute references" when trying to create a world map?

149 Views Asked by At

I'm currently doing a Python project where I am creating a world map visualization that highlights North, South, and Central America in different colors. When I run the code, no world map file is created. All the places where there is the syntax add are highlighted and it says "unresolved attribute reference 'add' for class Worldmap()".

Also, the render_to_file in wm.render_to_file is highlighted and it says "unresolved attribute reference 'render_to_file' for class Worldmap".

What do these errors mean and how may I fix them and get the map created? I've already looked and applied the information in the link below when trying to fix this: http://www.pygal.org/en/stable/documentation/types/maps/pygal_maps_world.html

Here is the relevant part of the code. I am using Python 3.9, Pygal 1.7, and the text editor Pycharms 2021.1.1 on a Mac.

import pygal

wm = pygal.Worldmap()
wm.title = "North, Central, and South America"
wm.add("North America", ["ca", "mx", "us"])
wm.add("Central America", ["bz", "cr", "gt", "hn", "ni", "pa", "sv"])
wm.add("South America", ["ar", "br" , "bo", "cl", "co", "ec", "gf", "gy", "pe", "py", "sr", "uy", "ve"])
wm.render_to_file("americas.svg")

This code comes from the book Python Crash Course. When the code within the book gave me those errors, I edited the code above to replicate the code within the link above such as having pygal.maps.world.World() instead of pygal.Worldmap(). It then gives me the error "cannot find references 'world() in __init.__py '

1

There are 1 best solutions below

3
tripleee On

The book author's web site notes that the library has been updated since the book went to press; their general comments and instructions are at https://ehmatthes.github.io/pcc/updates.html and the notes for Chapter 16 (which seems to be the one you are having trouble with) at https://ehmatthes.github.io/pcc/chapter_16/README.html#updates