4

This one is a famous question but int his scenario it's different and I couldn't find a solution which satisfy my problem. However this is it. I installed Python and Anaconda and Tensorflow in my computer like Tensorflow website describes.

And I installed it correctly and even tried example which provides by the Tensorflow website to check whether the Tensorflow working and it was succeeded. It runs in Anaconda prompt, Python prompt and python IDLE without a problem.

But when I try a script in Spyder and runs it in python console or ipython console, it gives me following error.

runfile('C:/Users/home/.spyder-py3/temp.py', wdir='C:/Users/home/.spyder-py3')
Traceback (most recent call last):

File "<ipython-input-2-4aa1bb797551>", line 1, in <module>
runfile('C:/Users/home/.spyder-py3/temp.py', wdir='C:/Users/home/.spyder-py3')

File "C:\Users\home\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
execfile(filename, namespace)

File "C:\Users\home\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)

File "C:/Users/home/.spyder-py3/temp.py", line 1, in <module>
import tensorflow as tf

ModuleNotFoundError: No module named 'tensorflow'

I don't know why is that and couldn't find a solution.

halfer
  • 19,824
  • 17
  • 99
  • 186
Ryan94
  • 321
  • 1
  • 5
  • 17
  • you probably have multiple versions of python installed on your system, and tensorflow is only installed on some of them – c2huc2hu Aug 02 '17 at 17:40
  • @user3080953 when I run import sys and sys.version, it only shows one version. – Ryan94 Aug 02 '17 at 17:42
  • The versions might be the same, but the installs could be different. Try `sys.executable` instead. that will give you the paths to the installation. – c2huc2hu Aug 02 '17 at 17:44
  • @user3080953 it gives only this. 'C:\\Users\\home\\AppData\\Local\\Programs\\Python\\Python35\\pythonw.exe'. – Ryan94 Aug 02 '17 at 17:50
  • it gives the same thing for spyder, python and ipython? – c2huc2hu Aug 02 '17 at 17:51
  • No. They are different. Anaconda prompt shows something else and idle shows another path. But both executes the import tensorflow as tf code. Also when I write import sys in spyder and press run, it doesn't give me an output. – Ryan94 Aug 02 '17 at 18:00
  • If it helps, using "Anaconda3 4.4.0" and running `conda install tensorflow` works for me. I believe this installs 1.1.0 – J'e Aug 02 '17 at 18:04

2 Answers2

4

I know it's an old question, but I found it useful to mention another way to solve it as follows:

  1. Install the tensorflow using conda, as described here, including the creation of a new environment...(You already mentioned that you did, but I'm adding it here as a reference for any new comer).
  2. From Anaconda Navigator, go to the top and select your new environment that you just created in the step1....(inspired by Rimma post on this question).
  3. Click install first for the application you want to install(Spyder or Jupyter..etc) then Click launch the application.
  4. Verify the installation by trying "import tensorflow as tf, as an example).

enter image description here

HassanSh__3571619
  • 1,859
  • 1
  • 19
  • 18
1

Same happened with me and these two help solving the issue:

1- create new environment and install python and tensorflow...Here is a video on YouTube for the same.!

2- Install spyder into the new environment that been created earlier. Follow these steps on the this link.!

HassanSh__3571619
  • 1,859
  • 1
  • 19
  • 18