Last modified: Jun 01, 2025 By Alexander Williams

Install Basemap Toolkit in Python

Basemap is a Python library for plotting geospatial data. It works well with Matplotlib. This guide will help you install it easily.

Prerequisites for Installing Basemap

Before installing Basemap, ensure you have Python installed. Python 3.6+ is recommended. You also need pip, the Python package installer.

Basemap requires Matplotlib and NumPy. Install them first if you don't have them.


# Install Matplotlib and NumPy
pip install matplotlib numpy

Install Basemap Using pip

The easiest way to install Basemap is via pip. Run this command in your terminal or command prompt.


pip install basemap

If you encounter errors, try installing the pre-built wheels. They are available for Windows and Linux.

Install Basemap from Source

If pip installation fails, you can install from source. First, download the source code from the official repository.


# Clone the Basemap repository
git clone https://github.com/matplotlib/basemap.git

Navigate to the cloned directory and run the setup script.


cd basemap
python setup.py install

Verify Basemap Installation

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


# Verify Basemap installation
from mpl_toolkits.basemap import Basemap
print("Basemap installed successfully!")


# Expected output
Basemap installed successfully!

Troubleshooting Common Issues

If you get errors, check your Python version. Basemap works best with Python 3.6-3.8.

On Windows, ensure you have Visual C++ Build Tools. They are required for some dependencies.

For Linux, install development libraries. Use your package manager.


# For Ubuntu/Debian
sudo apt-get install libgeos-dev

Using Basemap with GeoPandas

Basemap works well with GeoPandas. Together, they create powerful geospatial visualizations.

First, install GeoPandas. Then, use it to load shapefiles and plot them with Basemap.

Alternative Libraries

If Basemap doesn't work, try Rasterio or Fiona. They offer similar functionality.

Conclusion

Installing Basemap in Python is simple with pip. For advanced users, building from source is an option. Always verify the installation.

Basemap is great for geospatial data visualization. Pair it with GeoPandas for better results.