导入 TensorFlow 停止运行 python 程序 [英] Importing TensorFlow stops python program from running

查看:49
本文介绍了导入 TensorFlow 停止运行 python 程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在安装了 CPython 的 Visual Studios 中设置了 Python 工具.

I have Python Tools setup in Visual Studios with CPython installed.

在 Visual Studios 中,如果我运行以下代码:

In Visual Studios, if i run the following code:

print("hello");
import numpy;
print("hello");

程序运行正常,打印两个'hello',然后正常退出.

The program runs fine, prints two 'hello', and exits normally.

但是,如果我运行以下代码:

However, if I run the following code:

print("hello");
import tensorflow;
print("hello");

程序挂起,打印一个'hello',并拒绝继续.

The program hangs, prints one 'hello', and refuses to continue.

应正确安装所有软件包 - 在 Python 交互窗口中使用 TensorFlow 可打印正确的输出并完美运行.

All packages should be correctly installed - using the TensorFlow in the Python interactive window prints the correct output and works perfectly.

为什么程序会在第二种情况下挂掉?

Why does the program hang in the second scenario?

推荐答案

一旦你导入 tensorflow,它会自动尝试加载 cuda,它会打印如下内容:

Once you import tensorflow it automatically tries to load cuda, it prints something like this:

I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:128] successfully opened CUDA library libcurand.so locally

所以我认为正在发生的事情是您没有正确安装 cuda,因此它失败了.您可以尝试安装不使用 GPU 且不加载这些库的 CPU 版本.

So I think what is happening is that you don't have cuda installed correctly and it is failing because of it. You can try to install the CPU version which doesn't use the GPU and doesn't load those libraries.

这篇关于导入 TensorFlow 停止运行 python 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆