Last modified: Apr 03, 2025 By Alexander Williams

How to Install SpaCy in Python Step by Step

SpaCy is a powerful Python library for natural language processing (NLP). It helps with tasks like tokenization and named entity recognition. This guide will show you how to install SpaCy easily.

Prerequisites for Installing SpaCy

Before installing SpaCy, ensure you have Python installed. Python 3.6 or higher is recommended. You can check your Python version using python --version.

It's also good to have pip, Python's package manager. Most Python installations include pip by default. Verify pip is installed with pip --version.

Step 1: Install SpaCy Using Pip

The easiest way to install SpaCy is via pip. Open your command line or terminal and run:

 
pip install spacy

This command downloads and installs the latest SpaCy version. Wait for the installation to complete.

Step 2: Verify the Installation

After installation, verify SpaCy works. Open a Python shell and try importing it:

 
import spacy
print(spacy.__version__)

If you see the version number, SpaCy is installed correctly. If you get a ModuleNotFoundError, check our guide on solving ModuleNotFoundError.

Step 3: Download a Language Model

SpaCy requires language models for NLP tasks. Download a model using this command:

 
python -m spacy download en_core_web_sm

This downloads the small English model. Other models are available for different languages and sizes.

Step 4: Test the Language Model

Verify the model works with this example:

 
import spacy
nlp = spacy.load("en_core_web_sm")
doc = nlp("Hello, world!")
print([token.text for token in doc])


['Hello', ',', 'world', '!']

The output shows tokenized text. This confirms SpaCy is working properly.

Alternative Installation Methods

If pip doesn't work, try these alternatives:

Using Conda

For Anaconda users, install SpaCy with:

 
conda install -c conda-forge spacy

From Source

Advanced users can install from source:

 
git clone https://github.com/explosion/spaCy
cd spaCy
pip install -e .

Common Installation Issues

Some users face these problems:

Permission errors: Try adding --user to the pip command.

Slow downloads: Use a mirror with pip install -i flag.

Version conflicts: Create a virtual environment to isolate dependencies.

Upgrading SpaCy

Keep SpaCy updated with:

 
pip install --upgrade spacy

Also update language models when upgrading SpaCy.

Conclusion

Installing SpaCy is straightforward with pip. Remember to download a language model after installation. SpaCy is a valuable tool for any NLP project in Python.

For more complex setups, consider using virtual environments. If you encounter errors, our guide on ModuleNotFoundError can help troubleshoot installation issues.