Last modified: Jun 01, 2025 By Alexander Williams
Install pyshp for Shapefile Handling in Python
Shapefiles are a popular geospatial vector data format. The pyshp library makes it easy to work with them in Python. This guide will show you how to install and use it.
What is pyshp?
pyshp is a pure Python library for reading and writing ESRI Shapefiles. It has no dependencies and works with Python 2.7 and 3.x.
It provides simple tools for handling geospatial data. You can use it to parse, edit, and create shapefiles.
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, verify it works. Open a Python shell and try importing it:
import shapefile
print(shapefile.__version__)
If no errors appear, the installation was successful. You should see the version number printed.
Basic Usage Examples
Here's how to read a shapefile:
sf = shapefile.Reader("example.shp") # Load shapefile
shapes = sf.shapes() # Get all shapes
records = sf.records() # Get all records
To create a new shapefile:
w = shapefile.Writer("new_shapefile") # Create writer
w.field("NAME", "C") # Add field
w.point(1, 1) # Add point
w.record("Point 1") # Add record
w.close() # Save file
Handling Common Errors
If you get an import error, check the installation. Make sure you used the correct package name pyshp.
For file errors, verify the path is correct. Shapefiles require multiple files (.shp, .shx, .dbf).
Advanced Features
pyshp supports many shapefile operations. You can edit attributes, work with different geometry types, and more.
For big data projects, consider PyTables alongside pyshp.
Conclusion
pyshp is a powerful tool for shapefile handling in Python. It's easy to install and use for geospatial projects.
For similar Python installations, check our guides on PyGeoIP and dnspython.