我刚刚在机器上安装了Tensorflow的新版本,并且使用tensorflow-gpu创建了一个conda环境。

在激活环境的情况下,我在命令行中运行了典型的GPU利用率代码,以检查TF是否正在使用我的GPU,这很好。

import tensorflow as tf
with tf.device('/gpu:0'):
    a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
    b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
    c = tf.matmul(a, b)

with tf.Session() as sess:
    print (sess.run(c))


python - Tensorflow在PyCharm中不起作用-DLL加载失败:找不到特定的模块-LMLPHP

但是,当我尝试设置PyCharm在这种环境下使用解释器时,它只是失败了。运行配置和项目配置是相同的,并且应该使用gpu_env环境,但是在PyCharm中运行相同的检查代码时,它将失败并显示以下信息:

Traceback (most recent call last):
  File "C:/AccesaProjects/TFProj/tf_code.py", line 1, in <module>
    import tensorflow as tf
  File "C:\Users\radu.gheorghiu\AppData\Local\Continuum\anaconda3\envs\gpu_env\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "C:\Users\radu.gheorghiu\AppData\Local\Continuum\anaconda3\envs\gpu_env\lib\site-packages\tensorflow\python\__init__.py", line 47, in <module>
    import numpy as np
  File "C:\Users\radu.gheorghiu\AppData\Local\Continuum\anaconda3\envs\gpu_env\lib\site-packages\numpy\__init__.py", line 140, in <module>
    from . import _distributor_init
  File "C:\Users\radu.gheorghiu\AppData\Local\Continuum\anaconda3\envs\gpu_env\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
    from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.

Process finished with exit code 1


项目设置为:

python - Tensorflow在PyCharm中不起作用-DLL加载失败:找不到特定的模块-LMLPHP

并且“运行/调试”配置设置为:

python - Tensorflow在PyCharm中不起作用-DLL加载失败:找不到特定的模块-LMLPHP

几个月前,我上次尝试该方法时就可以使用,但现在还不确定什么不起作用。

任何提示将非常有帮助!谢谢!

最佳答案

问题似乎是特定于版本的,在这种情况下为2019.1。在解决此PyCharm错误之前,该解决方案更多是一种变通方法。

或者,您可以执行以下操作:


打开Anaconda终端
激活适当的环境
从终端启动PyCharm IDE

关于python - Tensorflow在PyCharm中不起作用-DLL加载失败:找不到特定的模块,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56025758/

10-13 07:34
查看更多