Last modified: Oct 06, 2026

How to Install Shapely in Python

Shapely is a Python library for geometric operations. It lets you create and manipulate points, lines, and polygons. You can measure areas, check intersections, and perform spatial queries. It is built on the GEOS library, which does the heavy geometric calculations.

Shapely is a core dependency for many geospatial tools. These include GeoPandas, Fiona, and Descartes. If you work with maps or spatial data, you will likely need Shapely. This guide shows you how to install it on any system.

Prerequisites

Before you install Shapely, check your Python version. Shapely 2.0 requires Python 3.8 or newer. Open a terminal and run this command:

 python --version 

You should see output like Python 3.11.4. If you have an older version, upgrade Python first. Also make sure pip is available. Run pip --version to check. If pip is missing, install it using your system package manager.

Method 1: Install Shapely with pip

The easiest way to install Shapely is with pip. Open your terminal or command prompt. Run this command:

 pip install shapely 

Pip will download the correct wheel for your operating system. A wheel is a pre-built package. It includes the GEOS library, so you do not need to install GEOS separately. This works on Windows, macOS, and most Linux distributions.

If you use a virtual environment, activate it first. Then run the pip command. Virtual environments keep your project dependencies isolated. This is a best practice for Python development.

Method 2: Install Shapely with conda

If you use Anaconda or Miniconda, install Shapely from the conda-forge channel. Run this command:

 conda install -c conda-forge shapely 

Conda handles the GEOS dependency automatically. It also manages version conflicts better than pip in some cases. This is the recommended method for Windows users who use Anaconda.

Method 3: Install Shapely from source

In rare cases, you may need to build Shapely from source. This requires a C compiler and the GEOS development headers. First, install GEOS on your system. On Ubuntu, run:

 sudo apt-get install libgeos-dev 

On macOS with Homebrew, run:

 brew install geos 

Then install Shapely using pip with the --no-binary flag:

 pip install shapely --no-binary shapely 

This method is slower and more error-prone. Only use it if the wheel installation fails.

Using a Virtual Environment

A virtual environment is a self-contained Python installation. It prevents package conflicts between projects. Create one with the venv module:

 python -m venv myenv 

Activate it on Windows:

 myenv\Scripts\activate 

Activate it on macOS or Linux:

 source myenv/bin/activate 

Then run pip install shapely inside the activated environment. This keeps your global Python installation clean.

Common Installation Errors and Fixes

You might see errors during installation. Here are the most common ones and how to solve them.

Error: GEOS library not found

This error appears when you build from source and GEOS is missing. The message says fatal error: geos_c.h: No such file or directory. Install the GEOS development package as shown in Method 3. On Windows, use conda instead of pip to avoid this error.

Error: Permission denied

On Linux or macOS, you might see Permission denied when installing globally. Do not use sudo pip install. Instead, use a virtual environment or add --user to the pip command:

 pip install --user shapely 

Error: Microsoft Visual C++ 14.0 is required

This Windows error occurs when pip tries to build from source. The solution is to install a pre-built wheel. Use conda, or upgrade pip and setuptools first:

 pip install --upgrade pip setuptools wheel 

Then try pip install shapely again. Modern wheels are available for most Windows configurations.

Error: Version conflict with other packages

Sometimes Shapely conflicts with GeoPandas or Fiona. Use a fresh virtual environment. Install packages in the correct order. Usually, install Shapely first, then GeoPandas.

Verifying Your Installation

After installation, open a Python interpreter. Run these commands to confirm Shapely works:

 import shapely print(shapely.__version__) 

You should see output like 2.0.1. If you see an ImportError, Shapely is not installed correctly. Check your Python environment and try reinstalling.

Now test a simple geometric operation. Create a point and buffer it:

 from shapely.geometry import Point # Create a point at coordinates (0, 0) point = Point(0, 0) # Create a buffer of radius 1 around the point buffered = point.buffer(1) # Print the area of the buffered circle print(buffered.area) 

The output should be approximately 3.14159. This confirms that Shapely and GEOS are working together correctly.

Example: Working with Polygons

Shapely can also handle polygons. Here is a quick example that creates a square and checks if a point is inside it:

 from shapely.geometry import Polygon, Point # Define a square polygon square = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)]) # Create a test point test_point = Point(0.5, 0.5) # Check if the point is inside the square print(square.contains(test_point)) 

The output is True. This demonstrates a basic spatial predicate. Shapely offers many more operations like intersection, union, and distance calculation.

Upgrading or Uninstalling Shapely

To upgrade Shapely to the latest version, run:

 pip install --upgrade shapely 

To uninstall Shapely, run:

 pip uninstall shapely 

Remember to uninstall inside the correct virtual environment if you use one.

Conclusion

Installing Shapely in Python is straightforward with pip or conda. Use pip for simplicity. Use conda if you already work with Anaconda. For Windows users, conda avoids many compilation headaches.

Always use a virtual environment to keep your projects isolated. Verify the installation by importing Shapely and checking the version. Then test a simple geometric operation like a buffer or containment check.

If you hit an error, check the common issues above. Missing GEOS, permission problems, and compiler errors are the most frequent. With the right approach, you will have Shapely running in minutes. Then you can start building powerful spatial analysis tools in Python.