Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
748 views
in Technique[技术] by (71.8m points)

can't import tensorflow in python, windows 10 64 bit

I am trying to make a AI chatbot using python. This requires tensorflow. I installed it using pip and when I try to import it, it isn't working. I got this Traceback:

Installation

C:Usersvross>pip3 install tensorflow
Requirement already satisfied: tensorflow in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (2.1.0)
Requirement already satisfied: astor>=0.6.0 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorflow) (0.8.1)
Requirement already satisfied: wrapt>=1.11.1 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorflow) (1.12.0)
Requirement already satisfied: gast==0.2.2 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorflow) (0.2.2)
Requirement already satisfied: grpcio>=1.8.6 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorflow) (1.27.2)
Requirement already satisfied: wheel>=0.26; python_version >= "3" in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorflow) (0.34.2)
Requirement already satisfied: scipy==1.4.1; python_version >= "3" in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorflow) (1.4.1)
Requirement already satisfied: google-pasta>=0.1.6 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorflow) (0.1.8)
Requirement already satisfied: keras-preprocessing>=1.1.0 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorflow) (1.1.0)
Requirement already satisfied: opt-einsum>=2.3.2 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorflow) (3.1.0)
Requirement already satisfied: tensorflow-estimator<2.2.0,>=2.1.0rc0 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorflow) (2.1.0)
Requirement already satisfied: six>=1.12.0 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorflow) (1.14.0)
Requirement already satisfied: keras-applications>=1.0.8 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorflow) (1.0.8)
Requirement already satisfied: numpy<2.0,>=1.16.0 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorflow) (1.18.1)
Requirement already satisfied: tensorboard<2.2.0,>=2.1.0 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorflow) (2.1.0)
Requirement already satisfied: termcolor>=1.1.0 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorflow) (1.1.0)
Requirement already satisfied: protobuf>=3.8.0 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorflow) (3.11.3)
Requirement already satisfied: absl-py>=0.7.0 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorflow) (0.9.0)
Requirement already satisfied: h5py in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from keras-applications>=1.0.8->tensorflow) (2.10.0)
Requirement already satisfied: requests<3,>=2.21.0 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow) (2.23.0)
Requirement already satisfied: werkzeug>=0.11.15 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow) (1.0.0)
Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow) (0.4.1)
Requirement already satisfied: markdown>=2.6.8 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow) (3.2.1)
Requirement already satisfied: setuptools>=41.0.0 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow) (45.2.0)
Requirement already satisfied: google-auth<2,>=1.6.3 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow) (1.11.2)
Requirement already satisfied: chardet<4,>=3.0.2 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from requests<3,>=2.21.0->tensorboard<2.2.0,>=2.1.0->tensorflow) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from requests<3,>=2.21.0->tensorboard<2.2.0,>=2.1.0->tensorflow) (2.9)
Requirement already satisfied: certifi>=2017.4.17 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from requests<3,>=2.21.0->tensorboard<2.2.0,>=2.1.0->tensorflow) (2019.11.28)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from requests<3,>=2.21.0->tensorboard<2.2.0,>=2.1.0->tensorflow) (1.25.8)
Requirement already satisfied: requests-oauthlib>=0.7.0 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.2.0,>=2.1.0->tensorflow) (1.3.0)
Requirement already satisfied: rsa<4.1,>=3.1.4 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from google-auth<2,>=1.6.3->tensorboard<2.2.0,>=2.1.0->tensorflow) (4.0)
Requirement already satisfied: cachetools<5.0,>=2.0.0 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from google-auth<2,>=1.6.3->tensorboard<2.2.0,>=2.1.0->tensorflow) (4.0.0)
Requirement already satisfied: pyasn1-modules>=0.2.1 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from google-auth<2,>=1.6.3->tensorboard<2.2.0,>=2.1.0->tensorflow) (0.2.8)
Requirement already satisfied: oauthlib>=3.0.0 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.2.0,>=2.1.0->tensorflow) (3.1.0)
Requirement already satisfied: pyasn1>=0.1.3 in c:usersvrossappdatalocalprogramspythonpython36libsite-packages (from rsa<4.1,>=3.1.4->google-auth<2,>=1.6.3->tensorboard<2.2.0,>=2.1.0->tensorflow) (0.4.8)

Interactive Session

C:Usersvross>python
Python 3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 13:35:33) [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:UsersvrossAppDataLocalProgramsPythonPython36libsite-packagesensorflow_corepythonpywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:UsersvrossAppDataLocalProgramsPythonPython36libsite-packagesensorflow_corepythonpywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:UsersvrossAppDataLocalProgramsPythonPython36libsite-packagesensorflow_corepythonpywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "C:UsersvrossAppDataLocalProgramsPythonPython36libimp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "C:UsersvrossAppDataLocalProgramsPythonPython36libimp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: Kan opgegeven module niet vinden.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:UsersvrossAppDataLocalProgramsPythonPython36libsite-packagesensorflow\__init__.py", line 101, in <module>
    from tensorflow_core import *
  File "C:UsersvrossAppDataLocalProgramsPythonPython36libsite-packagesensorflow_core\__init__.py", line 40, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "C:UsersvrossAppDataLocalProgramsPythonPython36libsite-packagesensorflow\__init__.py", line 50, in __getattr__
    module = self._load()
  File "C:UsersvrossAppDataLocalProgramsPythonPython36libsite-packagesensorflow\__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "C:UsersvrossAppDataLocalProgramsPythonPython36libimportlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:UsersvrossAppDataLocalProgramsPythonPython36libsite-packagesensorflow_corepython\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:UsersvrossAppDataLocalProgramsPythonPython36libsite-packagesensorflow_corepythonpywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:UsersvrossAppDataLocalProgramsPythonPython36libsite-packagesensorflow_corepythonpywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:UsersvrossAppDataLocalProgramsPythonPython36libsite-packagesensorflow_corepythonpywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:UsersvrossAppDataLocalProgramsPythonPython36libsite-packagesensorflow_corepythonpywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "C:UsersvrossAppDataLocalProgramsPythonPython36libimp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "C:UsersvrossAppDataLocalProgramsPythonPython36libimp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: Kan opgegeven module niet vinden. 
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Please follow the instructions from TensorFlow website. I recommend install Tensorflow 2, if you are using lower versions.

You need to download and install/update the Microsoft Visual C++ 2015-2019 Redistributable (x64) from here.

If you are facing any other issues possible reasons are

  • Your CPU does not support AVX2 instructions
  • Your CPU/Python is on 32 bits
  • There is a library that is in a different location/not installed on your system that cannot be loaded.

Please refer tested build configurations for windows CPU and GPU.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...