无法启动tensorflow 2.0

时间:2019-04-07 21:54:18

标签: python tensorflow

我无法将tensorflow 2.0模块导入我的代码中,但最终出现此错误

Traceback (most recent call last):
  File "C:\Users\Perseus\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\Perseus\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\Perseus\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\Perseus\Anaconda3\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\Perseus\Anaconda3\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Perseus\Anaconda3\lib\runpy.py", line 183, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "C:\Users\Perseus\Anaconda3\lib\runpy.py", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "C:\Users\Perseus\Anaconda3\lib\runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "C:\Users\Perseus\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 27, in <module>
    from tensorflow._api.v2 import audio
  File "C:\Users\Perseus\Anaconda3\lib\site-packages\tensorflow\_api\v2\audio\__init__.py", line 8, in <module>
    from tensorflow.python.ops.gen_audio_ops import decode_wav
  File "C:\Users\Perseus\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Users\Perseus\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Users\Perseus\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\Perseus\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\Perseus\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\Perseus\Anaconda3\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\Perseus\Anaconda3\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: The specified module could not be found.


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.

2 个答案:

答案 0 :(得分:1)

我认为您打了this bug

您可以将张量流降级为#include <cassert> #include <cstdint> #include <functional> #include <iostream> #include <map> #include <memory> class LogicOperation { public: virtual ~LogicOperation() = default; virtual bool operation(bool*, uint8_t count) = 0; }; using TCreateMethod = std::function<std::unique_ptr<LogicOperation>()>; class LogicOperationFactory { static std::map<std::string, TCreateMethod> s_methods; public: template<class T> static bool Register(const std::string& name) { std::map<std::string, TCreateMethod>::iterator it; it = s_methods.find(name); if (it != s_methods.end()) return false; s_methods[name] = []() -> std::unique_ptr<LogicOperation> { // Constructs an object of type T and wraps it in a std::unique_ptr return std::make_unique<T>(); // use default constructor }; return true; } static std::unique_ptr<LogicOperation> Create(const std::string& name) { auto iter = s_methods.find(name); return (iter != s_methods.end()) ? (iter->second)() : nullptr; } }; std::map<std::string, TCreateMethod> LogicOperationFactory::s_methods; class FooLogic : public LogicOperation { public: bool operation(bool*, uint8_t) override { std::cout << "FooLogic::operation" << std::endl; return true; } }; class BarLogic : public LogicOperation { public: bool operation(bool*, uint8_t) override { std::cout << "BarLogic::operation" << std::endl; return true; } }; static bool s_registeredFooLogic = LogicOperationFactory::Register<FooLogic>("FooLogic"); static bool s_registeredBarLogic = LogicOperationFactory::Register<BarLogic>("BarLogic"); int main() { assert(s_registeredFooLogic && s_registeredBarLogic); auto bar_logic = LogicOperationFactory::Create("BarLogic"); bool flag = false; bar_logic->operation(&flag, 1); auto null_logic = LogicOperationFactory::Create("ThisDoesNotExist"); assert(nullptr == null_logic); return 0; }

v1.10.0

或确保您具有CUDA,Tensorflow和CUDNN的以下版本:

  • CUDA v9.0
  • tensorflow-gpu v1.12.0
  • CUDNN 7.4.1.5

或者,您可以卸载tensorflow并通过conda安装它:

pip install tensorflow-gpu==1.10.0

答案 1 :(得分:0)

tensorflow 2.0现在正式可用。您可以重试。这次,如果正确安装了CUDA和CuDNN,它应该可以正常工作而不会出现任何错误。