SystemError: initialization of _internal failed without raising an exception

avatar
Borislav Hadzhiev

Last updated: Apr 10, 2024
3 min

banner

# Table of Contents

  1. SystemError: initialization of _internal failed without raising an exception
  2. Try to reinstall numba
  3. Restart the Jupyter Kernel
  4. The error is also caused by other packages

# SystemError: initialization of _internal failed without raising an exception

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.

shell
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

install numpy version 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.".

However, even though the error is shown, the package is installed successfully.

You can also try to run the command with the --force-reinstall flag.

shell
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

install numpy version 1 23 5 with force reinstall flag

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.

shell
pip show numpy pip3 show numpy python -m pip show numpy python3 -m pip show numpy

show current numpy version

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.

requirements.txt
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.

shell
pip install "numpy<=1.24.0" # Or with pip3 pip3 install "numpy<=1.24.0"

install version prior to 1 24 0

# Try to reinstall numba

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.

  1. First, uninstall numba.
shell
# 1) Uninstall numba pip uninstall numba pip3 uninstall numba python -m pip uninstall numba python3 -m pip uninstall numba

uninstall numba

  1. Now install the latest version of the numba module.
shell
# 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

upgrade numba version

# Restart the Jupyter Kernel

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

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 the package.
shell
# 1) Uninstall shap pip uninstall shap pip3 uninstall shap python -m pip uninstall shap python3 -m pip uninstall shap
  1. Install the latest version of the package.
shell
# 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.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev