Solving error – Illegal instruction (core dumped) after running import tensorflow

Solving error – Illegal instruction (core dumped) after running import tensorflow is an error which occurs when you have an old CPU that doesn’t work well with the version of Tensorflow you have.

This post is my attempt to explain to you why this error occurs and how you can solve it, I will also include multiple solutions that could be considered as alternative fixes to the error.

Exploring the Error : Illegal instruction (core dumped) after running import tensorflow

This is a tensorflow error which occurs when you have an old CPU that doesn’t work well with the version of Tensorflow you have.

The error should look like this. Double check in order to avoid mixing between errors.

                                                                       #
Illegal instruction (core dumped) after running import tensorflow
                                                                       #

Bellow are the solutions which worked for me and will help you to successfully solve your problem.

Solution 1 : Install the latest Tensorflow version using conda or downgrade Tensorflow

Apart from the obvious fix which is to buy a newer and better CPU ( I assume you are here because you do not want to do that).

The solution to the issue is to either Install the latest Tensorflow version using conda or downgrade Tensorflow.

You can downgrade Tensorflow easily by deleting your current version and installing an older version which will work well with your CPU.

We will focus on the second option, which is using conda in order to install Tensorflow.

To do that you should start with the command bellow.

                                                                       #
conda create -n tensorflow
                                                                       #

And Finally, you should install tensorflow-gpu using the command bellow.

                                                                       #
conda install tensorflow-gpu -n tensorflow
                                                                       #

The Conda fix is my preferred way to deal with this annoying error, I hope this was helpful to you.

If this solution does not fix your problem you can try the last fix bellow.

Solution 2 : install tensorflow with keras and a conda virtual environment.

This is the best solution if you want to keep you current Tensorflow version. Th solution is to install tensorflow with keras and a conda virtual environment.

First of all you should install conda and make sure it is working then you should create a conda virtual environment.

In your terminal use the command bellow

                                                                       #
conda create -n yourenvname python=x.x anaconda
                                                                       #

Where yourenvname is the name you chose for the environment and python=x.x is your python version depending on your case.

Next step is to install keras. This can be done by sing this command.

                                                                       #
pip install Keras-Applications
                                                                       #

And finally you can install tensorflow and everything should work as intended without downgrading your tensorflow version.

The solution should be enough, please try the final solution if this fails.

If this article has been useful for your particular case, consider donating to our Kofi account, there is a red button at the top of this page.

Summing-up

The article is over, I hope I have been able to help you solve this error or at least guide you in the right direction, check out other solutions to different errors you can do that by using the search bar on top of this page.

Keep learning, keep coding guys, cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/