python - 在anaconda环境中导入tensorflow时出现DLL错误
问题描述
我已经在 anaconda 环境中安装了 tensorflow。我已经通过“conda install tensorflow-gpu”安装了最新的 anaconda 和 tensorflow。当我尝试导入 tensorflow 时,它可以在 jupyter 笔记本中使用。但是,当我尝试从 python 终端运行或通过从 vs 代码“开始调试”运行时,确实会运行相同的代码。这是我得到的错误:
Traceback (most recent call last):
File "c:\Users\Admin\.vscode\extensions\ms-python.python-2019.4.12954\pythonFiles\ptvsd_launcher.py", line 43, in <module>
main(ptvsdArgs)
File "c:\Users\Admin\.vscode\extensions\ms-python.python-2019.4.12954\pythonFiles\lib\python\ptvsd\__main__.py", line 410, in main
run()
File "c:\Users\Admin\.vscode\extensions\ms-python.python-2019.4.12954\pythonFiles\lib\python\ptvsd\__main__.py", line 291, in run_file
runpy.run_path(target, run_name='__main__')
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "d:\Projects\SASRec\SASRec Pytorch\main.py", line 7, in <module>
import tensorflow as tf
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\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\Admin\Anaconda3\envs\tf-gpu\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Admin\Anaconda3\envs\tf-gpu\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
谁能给我一个解决方案,让我的生活更轻松。谢谢!
解决方案
在使用 Python 3.7 安装 Anaconda 并准备使用 TensorFlow 之前,您可能已经安装了某些版本的 python(例如 3.6.6)。因为 Anaconda 带有自己的 Python 实例,所以您已将 TensorFlow 依赖项安装到 Python 的 Anaconda 实例中。
当您使用控制台时,您很可能使用非 Anaconda-Python 实例,该实例没有安装 TensorFlow 及其所有依赖项。
您可以为非 Anaconda-Python 安装缺少的依赖项,或者使用 Anaconda 版本的 Python 启动脚本。您可以稍后通过使用完整路径调用 python/path/to/anaconda/bin/python yourscriptusingtensorflow.py
或将 anaconda 二进制路径添加到控制台的 $PATH 变量来完成。
推荐阅读
- c++ - C++ 链接器错误 LNK 2019 未解析的函数中引用的外部符号
- node.js - 使用$定位运算符+嵌入式文档+mongodb+nodejs编写复杂的搜索查询
- javascript - 我应该在我的 UI 组件库中的哪里包含 React 作为依赖项?
- angular - 表单数据作为 null 传递,除了角度 4 中的数据更新输入
- javascript - 将组件路由到 d3/event-drops 数据点时的 Angular 6 不会在 Safari 中显示
- php - 在一页中显示特定年份的记录
- javascript - 如果我删除或添加类到某个 jquery 元素,我可以添加一些触发的事件吗?
- rest - Contiki 中的 CoAP Max 交易是什么意思?
- nginx - NGINX 反向代理和 Access-Control-Allow-Origin 问题
- uml - 什么是合适的 UML 类关系?