我已经在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.
任何人都可以给我解决方案,让我的生活更轻松。谢谢!
答案 0 :(得分:2)
在使用Python 3.7安装Anaconda并准备使用TensorFlow之前,您可能已经安装了某些版本的python(例如3.6.6)。 由于Anaconda带有自己的Python实例,因此您已将TensorFlow依赖项安装到Python的Anaconda实例中。
使用控制台时,您很可能会使用非Anaconda-Python实例,该实例没有安装TensorFlow及其所有依赖项。
您可以为非Anaconda-Python安装缺少的依赖项,也可以使用Anaconda版本的Python启动脚本。您可以通过使用/path/to/anaconda/bin/python yourscriptusingtensorflow.py
之类的完整路径调用python或在控制台的$ PATH变量前添加anaconda二进制路径来完成此操作。
答案 1 :(得分:0)
因此,在大量安装,卸载和重新安装并刮掉github和stackoverflow中的各种类似问题之后,我得到了一个非常简单的解决方案。在我的系统中,我只安装了Anaconda和Microsoft(2019)的c ++构建工具,仅此而已。然后我按如下方式安装了tensorflow:
conda install tensorflow-gpu=1.10
显然,此旧版本与DLL兼容,并且一切似乎正常。