在Windows命令提示符下使用Tensorflow GPU执行python脚本

时间:2020-01-03 20:17:02

标签: python tensorflow

我正在尝试使用以下命令在Windows 10的命令提示符下执行Python脚本:

C:\Anaconda\envs\test\python testingc.py

但是当我有线

import tensorflow as tf

在Python脚本中,它给了我错误:

Traceback (most recent call last):
  File "C:\Anaconda\envs\test\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Anaconda\envs\test\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Anaconda\envs\test\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:\Anaconda\envs\test\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Anaconda\envs\test\lib\imp.py", line 342, 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 "testingc.py", line 41, in <module>
    import tensorflow as tf
  File "C:\Anaconda\envs\test\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "C:\Anaconda\envs\test\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Anaconda\envs\test\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Anaconda\envs\test\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Anaconda\envs\test\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Anaconda\envs\test\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:\Anaconda\envs\test\lib\imp.py", line 242, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Anaconda\envs\test\lib\imp.py", line 342, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: The specified module could not be found.

我注意到这仅在tensorflow-gpu中发生。如果在激活环境后在Anaconda Prompt上执行相同的脚本,则效果很好。

有什么方法可以在Windows的常规命令提示符中复制该行为?由于其他原因,我需要能够这样做。

在那个anaconda环境中,我有tensorflow-gpu = 1.13.1,python 3.7.4,cudatoolkit = 10.0.130和cudnn = 7.6.5。

0 个答案:

没有答案