Last modified: Jun 01, 2025 By Alexander Williams

Install pycountry in Python Easily

pycountry is a Python library for country and language data. It provides ISO standards for countries, languages, and currencies. This guide helps you install and use it.

What is pycountry?

pycountry gives access to ISO databases. It includes country names, languages, and currencies. It is useful for data validation and localization tasks.

Install pycountry Using pip

The easiest way to install pycountry is with pip. Open your terminal or command prompt and run:


pip install pycountry

This will download and install the latest version. If you need a specific version, specify it like this:


pip install pycountry==22.3.5

Verify the Installation

After installation, verify it works. Open Python and import the library:


import pycountry
print(pycountry.countries.get(alpha_2="US"))

The output should show the United States country data:


Country(alpha_2='US', alpha_3='USA', name='United States', numeric='840', official_name='United States of America')

Basic Usage of pycountry

pycountry provides several useful functions. Here are some examples:

Get Country by Code

Use pycountry.countries.get() to fetch country details:


country = pycountry.countries.get(alpha_2="GB")
print(country.name)

Output:


United Kingdom

List All Countries

To list all countries, iterate over pycountry.countries:


for country in pycountry.countries:
    print(country.name)

Get Language Data

pycountry also provides language data. Use pycountry.languages:


language = pycountry.languages.get(alpha_2="es")
print(language.name)

Output:


Spanish

Common Issues and Fixes

Sometimes, you may face issues. Here are common fixes.

ModuleNotFoundError

If you see ModuleNotFoundError, pycountry is not installed. Reinstall it using pip.

Outdated Version

Older versions may lack features. Always use the latest version.

Conclusion

pycountry is a powerful library for country and language data. It is easy to install and use. For similar tools, check GeoPandas or Cartopy.

Now you can integrate pycountry into your projects. Happy coding!