Text pre-processing 6. Troubleshooting
1. NumPy version issue
Note. This is an error that was found from intel Mac
Problem
You see an error related to NumPy, binary compatibility, or an older NumPy version.
Cause
Another installed package may require NumPy 1.x while NumPy 2.x is installed.
Solution
Activate your virtual environment, then run:
python -m pip install "numpy<2"
Check the installed version:
import numpy
print(numpy.__version__)
If the version starts with 1., run the original code again.
2. spaCy import error
Note. This is an error that was found from some PC users…
Problem
You may see the following error when running import spacy:
OSError: [WinError 1114] A dynamic link library (DLL) initialization routine failed.
Error loading "...torch\lib\c10.dll" or one of its dependencies.
Similar import problems can also occur on an Intel Mac, depending on the installed versions of spaCy and PyTorch.
Cause
spaCy’s dependency thinc may be unable to load a PyTorch library. PyTorch is not required for the text pre-processing exercises in this module.
Solution
If Python is running, exit it first:
exit()
Activate your virtual environment. On Windows, if the environment is named env_spacy, run:
.\env_spacy\Scripts\Activate.ps1
Then uninstall PyTorch:
python -m pip uninstall torch
Restart Python and test spaCy:
import spacy
print(spacy.__version__)
If the error continues, check the complete traceback. Start with the package or file named in the last error line.
3. Wrong Python environment
Note. This error often occurs when users mix their default Python environment with the virtual environment in which they installed spaCy.
Problem
You installed a package, but ModuleNotFoundError still occurs, or a different package version is displayed.
Cause
The Python used to install the package may be different from the Python used to run your code.
Solution
Run the following commands in a terminal, not at the Python prompt (>>>).
In VS Code, open Terminal > New Terminal and run the commands from your project folder. If you are currently in Python, exit first:
exit()
macOS
If your virtual environment is named env_spacy, activate it in the VS Code terminal:
source env_spacy/bin/activate
You can also run the commands in the macOS Terminal app. Move to your project folder first with cd:
cd path/to/your/project
source env_spacy/bin/activate
Windows
In the VS Code terminal, select PowerShell and activate the environment:
.\env_spacy\Scripts\Activate.ps1
If you are using Command Prompt instead of PowerShell, use:
env_spacy\Scripts\activate.bat
Check the active Python environment
Run these commands in the same terminal where the virtual environment is activated.
Check the location of the Python executable running your code:
python -c "import sys; print(sys.executable)"
Check the location of pip connected to that Python:
python -m pip --version
On macOS, the output should contain a path such as env_spacy/bin/python. On Windows, it should contain a path such as env_spacy\Scripts\python.exe. The two commands should point to the same virtual environment.
Install packages in this same terminal. Prefer python -m pip over pip so that the package is installed into the Python environment you just checked:
python -m pip install package-name
In VS Code, run Python: Select Interpreter, choose the same Python environment, open a new terminal, and try again.
What is a virtual environment?
A virtual environment is a separate Python workspace for a project. It prevents packages installed for one project from affecting other projects.
Remember these three points:
- Activate the virtual environment before running your code.
- Install packages into the activated environment.
- If a problem occurs, use
sys.executableto check the current environment.
Fixing Python REPL Indentation Problems in VS Code
If you encounter an indentation error when running Python code in VS Code (especially when using Shift+Enter to run selected lines), the issue may be related to Python 3.13’s new REPL auto-indentation behavior.
Option 1: Enable the Native REPL in VS Code
- Open VS Code Settings
- macOS:
Cmd + , - Windows/Linux:
Ctrl + ,
- macOS:
-
Search for:
Native REPL - Turn on the Native REPL setting.
This changes how VS Code sends selected Python code to the interactive Python environment and may resolve indentation problems.
Option 2: Use the Basic Python REPL
You can also bypass Python 3.13’s new REPL auto-indentation behavior by setting the following environment variable:
PYTHON_BASIC_REPL=1
On macOS or Linux, open a terminal and run:
export PYTHON_BASIC_REPL=1
Then launch VS Code from the same terminal:
code .
This setting applies only to that terminal session.
To make it persistent on macOS with zsh, add it to your ~/.zshrc file:
echo 'export PYTHON_BASIC_REPL=1' >> ~/.zshrc
source ~/.zshrc
What does this do?
Python 3.13 introduced a newer interactive REPL with automatic indentation. In some versions of VS Code, this can cause indentation problems when code is sent from the editor to the Python terminal.
Setting:
PYTHON_BASIC_REPL=1
tells Python to use the older, simpler REPL instead.
Note: If you normally run complete Python scripts using commands such as
python script.py, this issue generally does not affect you. It mainly occurs when running individual lines or selected code interactively in VS Code.