handson-ml icon indicating copy to clipboard operation
handson-ml copied to clipboard

chapter 9: Tensorflow does not work after installation

Open FritzPeleke opened this issue 6 years ago • 5 comments

C:\Users\fritz\PycharmProjects\venv\Scripts\python.exe C:/Users/fritz/PycharmProjects/Hello/Handson-ML-C9.py Traceback (most recent call last): File "C:\Users\fritz\PycharmProjects\venv\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in from tensorflow.python.pywrap_tensorflow_internal import * File "C:\Users\fritz\PycharmProjects\venv\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in _pywrap_tensorflow_internal = swig_import_helper() File "C:\Users\fritz\PycharmProjects\venv\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "C:\Program Files\Python37\lib\imp.py", line 242, in load_module return load_dynamic(name, filename, file) File "C:\Program Files\Python37\lib\imp.py", line 342, in load_dynamic return _load(spec) ImportError: DLL load failed: Eine DLL-Initialisierungsroutine ist fehlgeschlagen.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:/Users/fritz/PycharmProjects/Hello/Handson-ML-C9.py", line 1, in import tensorflow File "C:\Users\fritz\PycharmProjects\venv\lib\site-packages\tensorflow_init_.py", line 98, in from tensorflow_core import * File "C:\Users\fritz\PycharmProjects\venv\lib\site-packages\tensorflow_core_init_.py", line 40, in from tensorflow.python.tools import module_util as module_util File "C:\Users\fritz\PycharmProjects\venv\lib\site-packages\tensorflow_init.py", line 50, in getattr module = self.load() File "C:\Users\fritz\PycharmProjects\venv\lib\site-packages\tensorflow_init.py", line 44, in _load module = importlib.import_module(self.name) File "C:\Program Files\Python37\lib\importlib_init.py", line 127, in import_module return _bootstrap.gcd_import(name[level:], package, level) File "C:\Users\fritz\PycharmProjects\venv\lib\site-packages\tensorflow_core\python_init.py", line 49, in from tensorflow.python import pywrap_tensorflow File "C:\Users\fritz\PycharmProjects\venv\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 74, in raise ImportError(msg) ImportError: Traceback (most recent call last): File "C:\Users\fritz\PycharmProjects\venv\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in from tensorflow.python.pywrap_tensorflow_internal import * File "C:\Users\fritz\PycharmProjects\venv\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in _pywrap_tensorflow_internal = swig_import_helper() File "C:\Users\fritz\PycharmProjects\venv\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "C:\Program Files\Python37\lib\imp.py", line 242, in load_module return load_dynamic(name, filename, file) File "C:\Program Files\Python37\lib\imp.py", line 342, in load_dynamic return _load(spec) ImportError: DLL load failed: Eine DLL-Initialisierungsroutine ist fehlgeschlagen.

Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

for some common reasons and solutions. Include the entire stack trace above this error message when asking for help.

FritzPeleke avatar Nov 19 '19 21:11 FritzPeleke

Hi @FritzPeleke , Thanks for your feedback. Could you please give me more context? In particular, how exactly did you install TensorFlow? What version of TensorFlow are you trying to install? Are you trying to use a GPU?

I'll do my best to help you, but if you're running into a TensorFlow packaging issue, I might have to redirect you to the TensorFlow team (at https://github.com/tensorflow/tensorflow/issues).

ageron avatar Nov 21 '19 07:11 ageron

hi @ageron, it turns out pip installation of tensorflow has issues. I went through the internet and several others had the same issue. But installing it with conda solved the issue. so in case another person complains be sure to suggest installation with conda. 'conda install tensorflow'.

FritzPeleke avatar Nov 22 '19 00:11 FritzPeleke

I'm glad you found a solution. 👍 I'm not aware of any problem installing TensorFlow on Windows with pip (but I don't use Windows), could you please point me to the open issue regarding this problem? On MacOSX and Linux, there's definitely no problem (I just tried both). If you have a compatible NVIDIA GPU and you're trying to run TensorFlow-GPU, then you need to follow the instructions here. Cheers!

ageron avatar Nov 24 '19 14:11 ageron

hi, @ageron here are some links: https://github.com/tensorflow/tensorflow/issues/7623 https://github.com/tensorflow/tensorflow/issues/9469 But to use conda I had to downgrade to python 3.5 and tensorflow 1.10

FritzPeleke avatar Nov 25 '19 12:11 FritzPeleke

Hi @FritzPeleke ,

Thanks for the links. I got a Windows VM to run some tests, and indeed I had trouble installing TensorFlow 2.0 using pip. Now I remember that I also had issues when I ran some tests 3 years ago when writing the 1st edition, not just with TensorFlow but with other libraries as well, like Matplotlib (at the time), and that's why I added a footnote (page 43 in the second edition) that recommends using Anaconda on Windows. It also makes things much easier when using a GPU. Perhaps this should be a big warning rather than a small footnote. :/

In fact, I'm starting to think that there are very little downsides to using Anaconda (or Miniconda), and people should almost always prefer using it rather than pip / virtualenv. Environments are better isolated from the system, libraries come with all their dependencies nicely packaged, and if you really need the latest python library, you can always use pip with it (but then you might get the same DLL issues).

In the 3rd edition I think I'll show installation instructions using conda.

ageron avatar Dec 03 '19 03:12 ageron