Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing tensorflow makes python 3.6.5 error

Tensorflow used to work on my computer. But now when I try to import tensorflow python itself errors out. I am not given a traceback call to tell me what the error is. I get a window's prompt that says "Python has stopped working". When I click "debug" all I get is "An unhandled win32 exception occurred in python.exe". I've never had a python package actually error out python itself for me, I've always just had a traceback error thrown by python if I didn't install something right.

I've tried uninstalling and reinstalling tensorflow (effectively updating from 1.7.0 to 1.12.0) but that has not helped. I'm not sure how to search for a solution to this problem either since I'm not given a traceback or an error code or an error message aside from the very generic one above.

I'm currently using python 3.6.5 with tensorflow 1.12.0 (CPU only) installed. My OS is Windows 7 Enterprise 64 bit.

Any ideas?

EDIT: The python distro I am using is through Anaconda and I'm trying to run python directly through the anaconda prompt (command line interface).

EDIT2: I used the faulthandler module to see if I can get a stack trace out of it, and I got a Windows fatal exception: code 0xc0000139 and a Windows fatal exception: access violation, along with a bunch of lines linking to various frozen importlib._bootstrap lines of code in various __init__.py modules.

EDIT3: For a bit more context, this is on a workplace machine with a lot of security software installed on it.

like image 880
enumaris Avatar asked Nov 07 '18 23:11

enumaris


Video Answer


1 Answers

I have solved the issue. The following procedure was used to find and fix the problem:

I used the faulthandler module to force python to print out a stack trace and recieved a Windows fatal exception: access violation error which seems to suggest the problem was indeed a segfault caused by some module used by tensorflow.

I tried to fix dependencies by doing a conda update --all and then a conda clean --all which didn't fix the problem.

I noticed though that the problems seems to arise from the h5py and keras modules so I did pip install --upgrade h5py and pip install --upgrade keras and pip install --upgrade tensorflow and the problem was fixed. I am now using tensorflow version 1.12.0, keras version 2.2.4, and h5py version 2.8.0.

The key to solving this problem seems to be the faulthander module which showed me which modules (h5py and keras) were leading to the segfault.

like image 110
enumaris Avatar answered Oct 25 '22 07:10

enumaris