I cannot get pycountry_convert to work in my code

735 Views Asked by At

I came across this example to convert country to continent I could not find the package pycountry_convert so I installed pycontry and pycountry-convert but using both I cannot run the following code successfully.

I get this issue AttributeError: module 'pycountry' has no attribute 'country_alpha2_to_continent_code'

How do I get this piece of code to work or what do I need to install to do this function? I am using Pycharm with python 3.9

import pycountry_convert as pc

def country_to_continent(country_name):
    country_alpha2 = pc.country_name_to_country_alpha2(country_name)
    country_continent_code = pc.country_alpha2_to_continent_code(country_alpha2)
    country_continent_name = pc.convert_continent_code_to_continent_name(country_continent_code)
    return country_continent_name
0

There are 0 best solutions below