Last modified: Jun 09, 2025 By Alexander Williams

Install pyshp for Shapefile Handling

Working with Shapefiles in Python is easy with pyshp. This library helps read, write, and edit Shapefiles. Follow this guide to install and use it.

What is pyshp?

pyshp is a Python library for handling ESRI Shapefiles. It provides simple tools to work with geospatial data. No external dependencies are needed.

Install pyshp Using pip

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


pip install pyshp

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


pip install pyshp==2.1.0

Verify the Installation

After installing, check if pyshp works. Open a Python shell and import the library:

 
import shapefile
print("pyshp installed successfully!")


pyshp installed successfully!

Basic Usage of pyshp

Here’s a simple example to read a Shapefile. Save this code as read_shapefile.py:

 
import shapefile

# Load the Shapefile
sf = shapefile.Reader("example.shp")

# Get the shapes
shapes = sf.shapes()

# Print the first shape
print(shapes[0])

Run the script in your terminal:


python read_shapefile.py

This will display the first shape in the file. Replace example.shp with your file.

Writing a Shapefile

You can also create new Shapefiles. Here’s how to write a simple point Shapefile:

 
import shapefile

# Create a new Shapefile
w = shapefile.Writer("new_shapefile")

# Add a point
w.point(1, 1)

# Save the file
w.close()

This creates new_shapefile.shp in your working directory.

Common Issues and Fixes

If you get an error, check the file path. Also, ensure the Shapefile has all required parts (.shp, .shx, .dbf).

For more Python guides, see Install pygeoip in Python or Install dnspython.

Conclusion

pyshp is a powerful tool for Shapefile handling in Python. It’s easy to install and use. Try it for your geospatial projects today.

For more libraries, check PyCryptodome guide.