Search code examples
tensorflowkerasspyderimporterrorpython-3.8

Cannot import tensorflow in Spyder


When I run import keras in Spyder, the error message states that keras cannot find a tensorflow with version > 2.2

When I run import tensorflow, I get the following error message:

File "C:\Users\xxx\Anaconda3\Lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in from tensorflow.python._pywrap_tensorflow_internal import *

ImportError: DLL load failed while importing _pywrap_tensorflow_internal: Det går inte att hitta den angivna modulen.

(Last message in local tribal language translates as "Can not find the specified module")

I have installed keras and tensorflow via Anaconda using pip. The tensorflow version installed is 2.4.0, Keras 2.4.3 and Python 3.8

If I look in the folder C:\Users\xxx\Anaconda3\Lib\site-packages\tensorflow\python_pywrap_tensorflow_internal, there is a file called _pywrap_tensorflow_internal.lib I am not a Python expert, but I am guessing this file contains the binary code that should be called when the error is thrown ? The folder C:\Users\xxx\Anaconda3\Lib\site-packages is added to the Python path manager from within Spyder-

I used to being able to run Keras with this computer (Windows 10, x64). But since I formatted the hard drive and reinstalled everything from scratch it does not work. No GPU involved.

Sidenote: Some replies (1, 2) to similar questions on this site suggests it has to do with the Visual studio distribution. I have installed VS 2015, previously I used VS 2019. I would prefere not to install VS 2019 if it can be avoided


Solution

  • Installing the Microsoft Visual C++ 2015 Redistrutable Update 3 solved the problem. I think I found it here