pythonnlpspacy

Where to find spacy.py file to rename


I am attempting to install spacy and have tried a number of methods using pip, conda, and installing directing from git. However, I am running into the same error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[26], line 3
      1 import spacy
----> 3 nlp = spacy.load("en_core_web_sm")

AttributeError: module 'spacy' has no attribute 'load'

From reading various articles online like this one, I see that my error is likely due to a file called "spacy.py" that is causing a shadowing error. However, I can't find this file.

Using which python in my dir shows me:

/Users/my_name/anaconda3/bin/python

Looking into my anaconda3/bin/python dir, I do see a Unix Executable file named "spacy" but renaming it has not fixed my error.


Solution

  • Make sure you're also installing your preferred package:

    For pip:

    python -m spacy download en_core_web_sm
    

    Also, if you're using a virtual environment in your IDE, you should also run the following commands BEFORE installing spacy and your preferred package:

    For pip:

    python -m venv .env
    source .env/bin/activate
    

    For conda:

    conda create -n venv
    conda activate venv
    

    There could also be a mismatch between your environments. If you're using Anaconda, try installing spacy in the Anaconda Powershell. Otherwise, try installing spacy using conda and/or pip in your IDE's terminal.