Jean-Francois Gallant
Jean-Francois Gallant

Reputation: 14103

Tensorflow 1.7.1 error with python 3.5

I install tensorflow 1.7.1 to use with Unity ML-Agent. I install tensorflow with the following command:

pip3 install tensorflow==1.7.1

Installation goes fines but when I try to import tensorflow I got this error:

C:\>python
Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "C:\Python35_x64\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\Python35_x64\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 577, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 903, in create_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
ImportError: DLL load failed: Une routine d\u2019initialisation d\u2019une bibliothèque de liens dynamiques (DLL) a échoué.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python35_x64\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Python35_x64\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Python35_x64\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16, in swig_import_helper
    return importlib.import_module('_pywrap_tensorflow_internal')
  File "C:\Python35_x64\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python35_x64\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import *  # pylint: disable=redefined-builtin
  File "C:\Python35_x64\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Python35_x64\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Python35_x64\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\Python35_x64\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 577, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 903, in create_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
ImportError: DLL load failed: Une routine d\u2019initialisation d\u2019une bibliothèque de liens dynamiques (DLL) a échoué.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python35_x64\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Python35_x64\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Python35_x64\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16, in swig_import_helper
    return importlib.import_module('_pywrap_tensorflow_internal')
  File "C:\Python35_x64\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow_internal'


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

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

Microsoft C++ 2015 redistributable as installed on my system and I find MSVCP140.dll easily with the dos command ( like suggested in common installation issue docs ):

C:\>where MSVCP140.dll
C:\Windows\System32\msvcp140.dll

I don't install CUDA and cuDNN things because I don't have cuda cards and I only install tensorflow for CPU like suggested.

EDIT: Downgrading to TensorFlow 1.5 is not a solution for me because Unity ML-agents really need 1.7.1

Upvotes: 2

Views: 602

Answers (1)

Jean-Francois Gallant
Jean-Francois Gallant

Reputation: 14103

Finally it's a AVX support problem. My CPU don't support AVX instructions.

I compile myself the TensorFlow 1.7.1 from sources. Finally not that hard as I think ( but take few hours on my poor laptop). With GIT , CMAKE , SWIG and Python 3.5 I fellow the instruction on the tensorflow github repo ( readme.md ):

https://github.com/tensorflow/tensorflow/tree/v1.7.1/tensorflow/contrib/cmake

Everything goes fine except few " out of heap space " errors. Trying to add the flags /Zm200 , /Zm500 or anything else not working for me. I solve this issue by forcing to use 64bit VC compiler:

https://github.com/tensorflow/tensorflow/issues/11096

On this issue page , the user kalengi suggest some tips. I only use his commands for MSBuild:

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64\MSBuild.exe" /m:2 /p:CL_MPCount=1 /p:Configuration=Release /p:Platform=x64 /p:PreferredToolArchitecture=x64 ALL_BUILD.vcxproj

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64\MSBuild.exe" /m:2 /p:CL_MPCount=1 /p:Configuration=Release /p:Platform=x64 /p:PreferredToolArchitecture=x64 tf_python_build_pip_package.vcxproj

Upvotes: 1

Related Questions