简体   繁体   中英

Error when verifying tensorflow installed correctly

After installing tensorflow via this guide - https://github.com/jeffheaton/t81_558_deep_learning/blob/master/t81_558_class_01_1_overview.ipynb - I get an error that I do not understand. I can get into and then I active tf and get a prompt.

After install, I run the following code to verify installation:

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")

This is the error I get:

 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.

These are the packages I installed:

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

As a noob, I have tried to google the error, but every installation that I have come across with errors is not similar to mine.

The installation is via Juypter on a 3.6 kernel. All the packages installed correctly, but for some reason, verifying the install produces an error.

edit: Sorry, I forgot to include the code!

My current installation was a mess. I installed a couple of ide's, then python. The path was messed up, and it was a royal pain to troubleshoot.

I started with a fresh os install and I am doing it the right way.

Installing tensorflow can be a pain, especially if you need GPU support. Luckily it's gotten easier recently, and it is much easier than that guide makes it seem.

This one line should install the correct version of tensorflow-gpu, keras, and the appropriate cuda and cudnn toolkits:

conda install -c anaconda keras-gpu

I would just give it a go if you haven't already as it should just take a few minutes

Too much of a headache getting tf installed on my laptop.

Solution: AWS EC2 Ubuntu 18.04 (free tier), installed Tensorflow, doing remote development with VS Code locally.

I learned a ton setting up tf on Linux.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM