22

I am importing tensorflow in my ubuntu python using following commands-

$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Illegal instruction (core dumped)

And the program exits. Please specify the solution.

Aniket Velhankar
  • 411
  • 1
  • 4
  • 11

3 Answers3

24

I had the same problem and had to downgrade tensorflow to 1.5.0:

pip uninstall tensorflow
pip install tensorflow==1.5.0

Edit: As @Tobsta points out in the comments, the other option is to compile the binaries from source. The precompiled binaries of versions >1.5 use AVX instructions that are not supported by older CPUs

SheepPerplexed
  • 1,132
  • 8
  • 20
  • Actually I want to use the updated version of TF. I think downgrading won't be a solution. – Manikandan Balasubramanian Jun 06 '18 at 10:18
  • 6
    @MostwantedMani You'll have to build TensorFlow from source then, precompiled binaries for versions after 1.5.0 don't support some older CPUs (https://github.com/tensorflow/tensorflow/issues/18322) – Oliver Jun 19 '18 at 23:52
  • 1
    downgrading will not solve all the problems for sure, but did anyone tried to compile TF > 1.9.x version from source on an Older CPU ?? – codeNeverDie Jul 28 '18 at 12:58
  • after downgraded you will get for rasa line 4, in from keras.datasets import mnist ModuleNotFoundError: No module named 'keras' Process finished with exit code 1 can anyone help with this – Saurabh Chandra Patel Mar 01 '19 at 04:30
  • ERROR: Could not find a version that satisfies the requirement tensorflow==1.5.0 – don bright Aug 28 '21 at 16:58
3

I see same message on my PC / Celeron N4000.

$ python3 -c "import tensorflow as tf; print(tf.__version__)"
Illegal instruction (core dumped)

I successed to build TensorFlow v1.14.0 without AVX instruction. (Just build TensorFlow on CeleronN4000)

$ python3 -c "import tensorflow as tf; print(tf.__version__)"
1.14.0

I wrote the log on below.
https://github.com/naruai/wiki/blob/master/TensorFlow/BuildTensorFlowWOAVX.md

In my case, used Python 3.6.8 .
I also tested with Python 2.7 .
About Python 3.5 , I not tested.
Maybe possible to use similar way, I think.

naruai
  • 31
  • 3
3

The desired version of TensorFlow can be installed via a hack using anaconda. First, go to the directory which has sufficient space and download anaconda there (Check the version you want to install).

curl -O https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh

If you want to ensure the integrity of the Anaconda installed check it using SHA-256.

sha256sum Anaconda3-2019.03-Linux-x86_64.sh

Run the Anaconda Script:

bash Anaconda3-2019.03-Linux-x86_64.sh

Output should be like:

45c851b7497cc14d5ca060064394569f724b67d9b5f98a926ed49b834a6bb73a  Anaconda3-2019.03-Linux-x86_64.sh

Now when you get the prompt: Anaconda3 will be installed in this location: ….

Enter the location where you want it to be installed or press enter to continue.

Now as per your choice/requirement you can type yes/no for “Do you wish the installer to initialize Anaconda3 by running conda init?”

Now instead of using pip for installing tensorflow, we will use conda but for this we will have to first set the path using the vim ~/.bashrc file.

# added by Anaconda3 installer
export PATH="/anaconda3/bin:$PATH"

Put your own path instead of /anaconda3/bin, like: /data/anaconda3/bin, or whatsoever.

To make this effective, run:

source ~/.bashrc

Now create a virtual environment.

conda create -n tf_env
source /anaconda3/bin/activate tf_env

Now to install TensorFlow or Keras, run:

conda install tensorflow
conda install keras

or, if there is a particular version that you want to install say, version 1.14.0 for TensorFlow and 2.3.1 for Keras.

conda install tensorflow==1.14.0
conda install keras==2.3.1

You have to be in the same virtual environment as while installing Keras and/or TensorFlow for it to work properly. Tn this case tf_env by running source /anaconda3/bin/activate tf_env

You can check the installation by running

$ python3 -c "import tensorflow as tf; print(tf.__version__)"
1.14.0
Satyam
  • 393
  • 1
  • 5
  • 16