【问题标题】:Error when verifying tensorflow installed correctly验证正确安装 tensorflow 时出错
【发布时间】:2019-09-04 03:08:11
【问题描述】:

通过本指南安装 tensorflow - https://github.com/jeffheaton/t81_558_deep_learning/blob/master/t81_558_class_01_1_overview.ipynb - 我收到一个我不明白的错误。我可以进入然后我激活 tf 并得到提示。

安装后,我运行以下代码来验证安装:

import sys

    import tensorflow.keras
    import pandas as pd
    import sklearn as sk
    import tensorflow as tf

    print(f"Tensor Flow Version: {tf.__version__}")
    print(f"Keras Version: {tensorflow.keras.__version__}")
    print()
    print(f"Python {sys.version}")
    print(f"Pandas {pd.__version__}")
    print(f"Scikit-Learn {sk.__version__}")
    print("GPU is", "available" if tf.test.is_gpu_available() else "NOT AVAILABLE")

这是我得到的错误:

 ImportError                               Traceback (most recent call last)
        ~\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
             57 
        ---> 58   from tensorflow.python.pywrap_tensorflow_internal import *
             59   from tensorflow.python.pywrap_tensorflow_internal import __version__

        ~\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in <module>
             27             return _mod
        ---> 28     _pywrap_tensorflow_internal = swig_import_helper()
             29     del swig_import_helper

        ~\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in swig_import_helper()
             23             try:
        ---> 24                 _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
             25             finally:

        ~\Anaconda3\lib\imp.py in load_module(name, file, filename, details)
            241         else:
        --> 242             return load_dynamic(name, filename, file)
            243     elif type_ == PKG_DIRECTORY:

        ~\Anaconda3\lib\imp.py in load_dynamic(name, path, file)
            341             name=name, loader=loader, origin=path)
        --> 342         return _load(spec)
            343 

        ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.

        During handling of the above exception, another exception occurred:

        ImportError                               Traceback (most recent call last)
        <ipython-input-2-0b3eb45acbe5> in <module>
              1 import sys
              2 
        ----> 3 import tensorflow.keras
              4 import pandas as pd
              5 import sklearn as sk

        ~\Anaconda3\lib\site-packages\tensorflow\__init__.py in <module>
             38 import sys as _sys
             39 
        ---> 40 from tensorflow.python.tools import module_util as _module_util
             41 
             42 from tensorflow._api.v2 import audio

        ~\Anaconda3\lib\site-packages\tensorflow\python\__init__.py in <module>
             47 import numpy as np
             48 
        ---> 49 from tensorflow.python import pywrap_tensorflow
             50 
             51 # Protocol buffers

        ~\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
             72 for some common reasons and solutions.  Include the entire stack trace
             73 above this error message when asking for help.""" % traceback.format_exc()
        ---> 74   raise ImportError(msg)
             75 
             76 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line-too-long

        ImportError: Traceback (most recent call last):
          File "C:\Users\madew\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
            from tensorflow.python.pywrap_tensorflow_internal import *
          File "C:\Users\madew\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
            _pywrap_tensorflow_internal = swig_import_helper()
          File "C:\Users\madew\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
            _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
          File "C:\Users\madew\Anaconda3\lib\imp.py", line 242, in load_module
            return load_dynamic(name, filename, file)
          File "C:\Users\madew\Anaconda3\lib\imp.py", line 342, in load_dynamic
            return _load(spec)
        ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.


        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.

这些是我安装的包:

pip install --exists-action i --upgrade sklearn
pip install --exists-action i --upgrade pandas
pip install --exists-action i --upgrade pandas-datareader
pip install --exists-action i --upgrade matplotlib
pip install --exists-action i --upgrade pillow
pip install --exists-action i --upgrade tqdm
pip install --exists-action i --upgrade requests
pip install --exists-action i --upgrade h5py
pip install --exists-action i --upgrade pyyaml
pip install --exists-action i --upgrade tensorflow_hub
pip install --exists-action i --upgrade bayesian-optimization
pip install --exists-action i --upgrade spacy
pip install --exists-action i --upgrade gensim
pip install --exists-action i --upgrade flask
pip install --exists-action i --upgrade boto3
pip install --exists-action i --upgrade gym
pip install --exists-action i --upgrade tensorflow==2.0.0-beta1
pip install --exists-action i --upgrade keras-rl2 --user

作为一个菜鸟,我尝试用谷歌搜索错误,但我遇到的每个安装错误都与我的不同。

安装是通过 Juypter 在 3.6 内核上进行的。所有软件包都安装正确,但由于某种原因,验证安装会产生错误。

编辑:对不起,我忘了包含代码!

【问题讨论】:

标签: python-3.x tensorflow jupyter-notebook


【解决方案1】:

在我的笔记本电脑上安装 tf 太让人头疼了。

解决方案: AWS EC2 Ubuntu 18.04(免费套餐),安装 Tensorflow,在本地使用 VS Code 进行远程开发。

我学到了很多在 Linux 上设置 tf 的知识。

【讨论】:

    【解决方案2】:

    我当前的安装是一团糟。我安装了几个 ide,然后是 python。路径一团糟,要进行故障排除非常痛苦。

    我从一个全新的操作系统安装开始,并且以正确的方式进行操作。

    【讨论】:

    • 它不工作。我在笔记本电脑上进行了全新安装,但无济于事。有兼容性问题什么的。在我自己的本地环境中工作会很好,但现在,Colabs 可以。到目前为止,我已经花了大约 18 个小时进行故障排除,这段时间可以用来学习,当我有更多经验时,我会再次尝试安装。
    【解决方案3】:

    安装 tensorflow 可能会很痛苦,尤其是在您需要 GPU 支持的情况下。幸运的是,它最近变得更容易了,而且比该指南看起来要容易得多。

    这一行应该安装正确版本的 tensorflow-gpu、keras 以及相应的 cuda 和 cudnn 工具包:

    conda install -c anaconda keras-gpu
    

    如果你还没有,我会试一试,因为它应该只需要几分钟

    【讨论】:

      猜你喜欢
      • 2018-07-26
      • 1970-01-01
      • 2020-04-18
      • 2021-09-16
      • 2016-04-17
      • 2016-03-19
      • 1970-01-01
      • 1970-01-01
      • 2012-07-20
      相关资源
      最近更新 更多