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

让人想犯罪 __ 提交于 2020-05-09 07:54:27

问题


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:\Users\vross>pip3 install tensorflow
Requirement already satisfied: tensorflow in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (2.1.0)
Requirement already satisfied: astor>=0.6.0 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorflow) (0.8.1)
Requirement already satisfied: wrapt>=1.11.1 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorflow) (1.12.0)
Requirement already satisfied: gast==0.2.2 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorflow) (0.2.2)
Requirement already satisfied: grpcio>=1.8.6 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorflow) (1.27.2)
Requirement already satisfied: wheel>=0.26; python_version >= "3" in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorflow) (0.34.2)
Requirement already satisfied: scipy==1.4.1; python_version >= "3" in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorflow) (1.4.1)
Requirement already satisfied: google-pasta>=0.1.6 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorflow) (0.1.8)
Requirement already satisfied: keras-preprocessing>=1.1.0 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorflow) (1.1.0)
Requirement already satisfied: opt-einsum>=2.3.2 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorflow) (3.1.0)
Requirement already satisfied: tensorflow-estimator<2.2.0,>=2.1.0rc0 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorflow) (2.1.0)
Requirement already satisfied: six>=1.12.0 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorflow) (1.14.0)
Requirement already satisfied: keras-applications>=1.0.8 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorflow) (1.0.8)
Requirement already satisfied: numpy<2.0,>=1.16.0 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorflow) (1.18.1)
Requirement already satisfied: tensorboard<2.2.0,>=2.1.0 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorflow) (2.1.0)
Requirement already satisfied: termcolor>=1.1.0 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorflow) (1.1.0)
Requirement already satisfied: protobuf>=3.8.0 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorflow) (3.11.3)
Requirement already satisfied: absl-py>=0.7.0 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorflow) (0.9.0)
Requirement already satisfied: h5py in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from keras-applications>=1.0.8->tensorflow) (2.10.0)
Requirement already satisfied: requests<3,>=2.21.0 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow) (2.23.0)
Requirement already satisfied: werkzeug>=0.11.15 in c:\users\vross\appdata\local\programs\python\python36\lib\site-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:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow) (0.4.1)
Requirement already satisfied: markdown>=2.6.8 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow) (3.2.1)
Requirement already satisfied: setuptools>=41.0.0 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow) (45.2.0)
Requirement already satisfied: google-auth<2,>=1.6.3 in c:\users\vross\appdata\local\programs\python\python36\lib\site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow) (1.11.2)
Requirement already satisfied: chardet<4,>=3.0.2 in c:\users\vross\appdata\local\programs\python\python36\lib\site-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:\users\vross\appdata\local\programs\python\python36\lib\site-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:\users\vross\appdata\local\programs\python\python36\lib\site-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:\users\vross\appdata\local\programs\python\python36\lib\site-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:\users\vross\appdata\local\programs\python\python36\lib\site-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:\users\vross\appdata\local\programs\python\python36\lib\site-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:\users\vross\appdata\local\programs\python\python36\lib\site-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:\users\vross\appdata\local\programs\python\python36\lib\site-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:\users\vross\appdata\local\programs\python\python36\lib\site-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:\users\vross\appdata\local\programs\python\python36\lib\site-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:\Users\vross>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:\Users\vross\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\vross\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\vross\AppData\Local\Programs\Python\Python36\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:\Users\vross\AppData\Local\Programs\Python\Python36\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\vross\AppData\Local\Programs\Python\Python36\lib\imp.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:\Users\vross\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\__init__.py", line 101, in <module>
    from tensorflow_core import *
  File "C:\Users\vross\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "C:\Users\vross\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
    module = self._load()
  File "C:\Users\vross\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\__init__.py", line 44, in _load
    module = _importlib.import_module(self.__name__)
  File "C:\Users\vross\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\vross\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Users\vross\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Users\vross\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\vross\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\vross\AppData\Local\Programs\Python\Python36\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:\Users\vross\AppData\Local\Programs\Python\Python36\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\vross\AppData\Local\Programs\Python\Python36\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: Kan opgegeven module niet vinden. 

回答1:


Please follow the instructions from TensorFlow website. I recommend please 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.



来源:https://stackoverflow.com/questions/60319768/cant-import-tensorflow-in-python-windows-10-64-bit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!