Anyone know why this is not working properly. According to https://pypi.org/project/iso3166/ this should work.
from iso3166 import countries
Get following error:
ImportError: cannot import name 'countries' from 'iso3166'
Anyone know why this is not working properly. According to https://pypi.org/project/iso3166/ this should work.
from iso3166 import countries
Get following error:
ImportError: cannot import name 'countries' from 'iso3166'
You can also use countrywrangler which should also be a bit faster.
pip install countrywrangler
Here is an example code:
import countrywrangler as cw
alpha2 = cw.Normalize.name_to_alpha2("Germany")
print(alpha2)
>>> DE
There is also a fuzzy option that matches virtually any different formatting:
import countrywrangler as cw
alpha2 = cw.Normalize.name_to_alpha2("Germany Federal Republic of", use_fuzzy=True)
print(alpha2)
>>> DE
I ran into this same issue which stemmed using an in-line pip install from my Jupyter notebook. Here a few common solutions worth trying:
Here is what worked for me:
If that still doesn't work for you, consider trying a different library, like this one: https://pypi.org/project/pycountry/