Last updated: Apr 10, 2024
Reading timeยท3 min
The error "SystemError: initialization of _internal failed without raising an exception" occurs because of an issue introduced with NumPy version 1.24.
To solve the error, install NumPy version
1.23.5
and pin your NumPy version.
Open your terminal in your project's root directory and run the following command.
pip install numpy==1.23.5 pip3 install numpy==1.23.5 # ๐๏ธ If you don't have pip in PATH environment variable python -m pip install numpy==1.23.5 python3 -m pip install numpy==1.23.5 # ๐๏ธ py alias (Windows) py -m pip install numpy==1.23.5 # ๐๏ธ For Jupyter Notebook !pip install numpy==1.23.5
When you run the command, you might get an error that states "ERROR: pip's dependency resolver does not currently take into account all the packages that are installed.".
You can also try to run the command with the --force-reinstall flag.
pip install numpy==1.23.5 --force-reinstall pip3 install numpy==1.23.5 --force-reinstall # ๐๏ธ If you don't have pip in PATH environment variable python -m pip install numpy==1.23.5 --force-reinstall python3 -m pip install numpy==1.23.5 --force-reinstall # ๐๏ธ py alias (Windows) py -m pip install numpy==1.23.5 --force-reinstall # ๐๏ธ For Jupyter Notebook !pip install numpy==1.23.5 --force-reinstall
The --force-reinstall
option reinstalls the specified packages even if they
are already up-to-date.
You can check your current NumPy version with the pip show numpy
command.
pip show numpy pip3 show numpy python -m pip show numpy python3 -m pip show numpy
If you have a requirements.txt
file, pin your version of the numpy
module to
1.23.5
so you don't get the error the next time you install your modules.
numpy==1.23.5
The error "SystemError: initialization of _internal failed without raising an exception" means that a module failed to initialize and returned an error code, however, no exception was raised with the error code.
1.23.5
is the last NumPy version before the 1.24.0
release that caused the
issue.
In other words, you can also install version "numpy<=1.24.0"
to achieve the
same result.
pip install "numpy<=1.24.0" # Or with pip3 pip3 install "numpy<=1.24.0"
The error is also caused by having an outdated version of the numba
module.
Open your terminal and upgrade the module to the latest version.
numba
.# 1) Uninstall numba pip uninstall numba pip3 uninstall numba python -m pip uninstall numba python3 -m pip uninstall numba
numba
module.# 2) Install latest version of `numba` pip install numba --upgrade pip3 install numba --upgrade python -m pip install numba --upgrade python3 -m pip install numba --upgrade
If the error persists and you use Jupyter Notebook, try restarting the Jupyter Kernel.
You can follow the instructions in this article if you need an illustrated guide.
The error is also caused by other packages, e.g. shap
.
Your error message should contain information as to which package caused the issue if you scroll up in your terminal.
For example, if the shap
package caused your issue, you have to:
# 1) Uninstall shap pip uninstall shap pip3 uninstall shap python -m pip uninstall shap python3 -m pip uninstall shap
# 2) Install the latest version pip install shap --upgrade pip3 install shap --upgrade python -m pip install shap --upgrade python3 -m pip install shap --upgrade
When you run the command, you might get an error that states "ERROR: pip's dependency resolver does not currently take into account all the packages that are installed.".
However, even though the error is shown, the package is installed successfully.
You can learn more about the related topics by checking out the following tutorials: