AttributeError: module 'spacy' has no attribute 'load'
Asked Answered
P

3

7
import spacy
nlp = spacy.load('en_core_web_sm')

**Error:** Traceback (most recent call last):

  File "C:\Users\PavanKumar\.spyder-py3\ExcelML.py", line 27, in <module>
    nlp = spacy.load('en_core_web_sm')

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

Can anyone suggest me a solution?

Preraphaelite answered 31/5, 2021 at 6:42 Comment(1)
Do you have a file named spacy.py in your directory? If so you should change the name, that might cause this issue.Devoted
L
38

Don't name the file spacy.py, it will create conflict.

Leopold answered 20/11, 2021 at 4:42 Comment(0)
A
3

Try installing spacy again, I had the same problem, after running conda install spacy and restarting my notebook kernel it worked. For the complete installation documentation check the spacy official website: spacy documentation

Arcograph answered 16/6, 2021 at 9:37 Comment(0)
S
0

I had the same problem, and it turned out the error was caused by naming the file 'spacy', apparently it creates a naming conflict. In Python distinctive files are modules, and therefore by naming it 'spacy', you overwrite the file and import itself. Consequently, you should not name your files with package names and they will work well. Once I renamed the file into something else, it worked flawlessly. enter image description here

Slipway answered 27/9, 2022 at 12:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.