I'm new to Python and I was given this code by my professor which includes "import spacy" and when I run the code I get the line: ModuleNotFoundError: No module named 'spacy'
That's where I got stuck I tried pip install spacy
and many other commands in VS Code terminal but nothing works. I've tried some solutions shared on stackoverflow but none of them work and they all give similar errors. I have the latest version of python installed (3.13.3)
When I run pip install spacy
I get this:
$ pip install spacy
PS C:\Users\----\Desktop\Courses\CKA\Exercises\Exercise 1 to 5\Exercise 1 to 5> & C:/Users/----/AppData/Local/Programs/Python/Python313/python.exe "c:/Users/----/Desktop/Courses/CKA/Exercises/Exercise 1 to 5/Exercise 1 to 5/Exercise3.py"
Traceback (most recent call last):
File "c:\Users\----\Desktop\Courses\CKA\Exercises\Exercise 1 to 5\Exercise 1 to 5\Exercise3.py", line 1, in <module>
import spacy
ModuleNotFoundError: No module named 'spacy'
PS C:\Users\----\Desktop\Courses\CKA\Exercises\Exercise 1 to 5\Exercise 1 to 5> pip install spacy
Collecting spacy
Using cached spacy-3.8.2.tar.gz (1.3 MB)
Installing build dependencies ... error
error: subprocess-exited-with-error
× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> [67 lines of output]
Ignoring numpy: markers 'python_version < "3.9"' don't match your environment
Collecting setuptools
Using cached setuptools-80.7.1-py3-none-any.whl.metadata (6.6 kB)
Collecting cython<3.0,>=0.25
Using cached Cython-0.29.37-py2.py3-none-any.whl.metadata (3.1 kB)
Collecting cymem<2.1.0,>=2.0.2
Using cached cymem-2.0.11-cp313-cp313-win_amd64.whl.metadata (8.8 kB)
Collecting preshed<3.1.0,>=3.0.2
Using cached preshed-3.0.9.tar.gz (14 kB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Preparing metadata (pyproject.toml): started
Preparing metadata (pyproject.toml): finished with status 'done'
Collecting murmurhash<1.1.0,>=0.28.0
Using cached murmurhash-1.0.12-cp313-cp313-win_amd64.whl.metadata (2.2 kB)
Collecting thinc<8.4.0,>=8.3.0
Using cached thinc-8.3.6-cp313-cp313-win_amd64.whl.metadata (15 kB)
Collecting numpy<2.1.0,>=2.0.0
Using cached numpy-2.0.2.tar.gz (18.9 MB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Installing backend dependencies: started
Installing backend dependencies: finished with status 'done'
Preparing metadata (pyproject.toml): started
Preparing metadata (pyproject.toml): finished with status 'error'
error: subprocess-exited-with-error
Preparing metadata (pyproject.toml) did not run successfully.
exit code: 1
[21 lines of output]
+ C:\Users\----\AppData\Local\Programs\Python\Python313\python.exe C:\Users\----\AppData\Local\Temp\pip-install-ww0vaoa9\numpy_133065237a5a4e9dbdd300bd2c67b165\vendored-meson\meson\meson.py setup C:\Users\----\AppData\Local\Temp\pip-install-ww0vaoa9\numpy_133065237a5a4e9dbdd300bd2c67b165 C:\Users\----\AppData\Local\Temp\pip-install-ww0vaoa9\numpy_133065237a5a4e9dbdd300bd2c67b165\.mesonpy-lghusuj7 -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=C:\Users\----\AppData\Local\Temp\pip-install-ww0vaoa9\numpy_133065237a5a4e9dbdd300bd2c67b165\.mesonpy-lghusuj7\meson-python-native-file.ini
The Meson build system
Version: 1.4.99
Source dir: C:\Users\----\AppData\Local\Temp\pip-install-ww0vaoa9\numpy_133065237a5a4e9dbdd300bd2c67b165
Build dir: C:\Users\----\AppData\Local\Temp\pip-install-ww0vaoa9\numpy_133065237a5a4e9dbdd300bd2c67b165\.mesonpy-lghusuj7
Build type: native build
Project name: NumPy
Project version: 2.0.2
WARNING: Failed to activate VS environment: Could not find C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe
..\meson.build:1:0: ERROR: Unknown compiler(s): [['icl'], ['cl'], ['cc'], ['gcc'], ['clang'], ['clang-cl'], ['pgcc']]
The following exception(s) were encountered:
Running `icl ""` gave "[WinError 2] The system cannot find the file specified"
Running `cl /?` gave "[WinError 2] The system cannot find the file specified"
Running `cc --version` gave "[WinError 2] The system cannot find the file specified"
Running `gcc --version` gave "[WinError 2] The system cannot find the file specified"
Running `clang --version` gave "[WinError 2] The system cannot find the file specified"
Running `clang-cl /?` gave "[WinError 2] The system cannot find the file specified"
Running `pgcc --version` gave "[WinError 2] The system cannot find the file specified"
A full log can be found at C:\Users\----\AppData\Local\Temp\pip-install-ww0vaoa9\numpy_133065237a5a4e9dbdd300bd2c67b165\.mesonpy-lghusuj7\meson-logs\meson-log.txt
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
Encountered error while generating package metadata.
See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
At the time of writing (May 17 2025), spacy does not seem to support Python 3.13 (the version you seem to be using).
Use Python 3.12 instead, for example with uv
or conda
(via for example micromamba
).
Here's the relevant Github issue: Spacy installation on python 3.13 fails