TensorFlow部分导入

发布于 2025-01-20 11:53:21 字数 321 浏览 0 评论 0 原文

当我运行脚本并从CMD或Visual Studio代码导入TensorFlow时,它会给我带来错误

but when I run it from Anaconda prompt or Spyder it works well. 为什么会发生???我必须添加任何路径吗?

When I run a script and import Tensorflow from cmd or Visual Studio Code it throws me the error
enter image description here

but when I run it from Anaconda prompt or Spyder it works well.
Why does this happen??? DO I have to add anything to PATH?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅暮の光 2025-01-27 11:53:21

这是由于 python TensorFlow 仅安装在Anaconda环境中。

  1. 要访问 TensorFlow 从命令提示符而不是 anaconda提示,您需要按照以下步骤操作:

open 命令提示当管理员(通过右键单击并选择运行为管理员)

C:\windows\system32\python   # (This will show if python is installed in this directory or can install the latest python)
C:\windows\system32\pip install --upgrade pip 
C:\windows\system32\pip install tensorflow (to install tensorflow in same path)
C:\windows\system32\python>>import tensorflow as tf >>print(tf.__version__) #to check if tensorflow installed successfully and is accessible
  1. 通过VS代码访问 TensorFlow ,您需要安装 python扩展名 vs code post在系统中安装VS代码。成功安装扩展程序后,您可以单击“创建新的Jupyter笔记本”,然后选择适当的Python解释器,如Anaconda中。

现在,VS代码可以运行 TensorFlow 代码。
请检查 this 供您参考的链接。

This is due to Python and TensorFlow being installed only in your anaconda environment.

  1. To access TensorFlow from command prompt rather than anaconda prompt , you need to follow the steps below:

Open command prompt as administrator (by right click and selecting run as administrator)

C:\windows\system32\python   # (This will show if python is installed in this directory or can install the latest python)
C:\windows\system32\pip install --upgrade pip 
C:\windows\system32\pip install tensorflow (to install tensorflow in same path)
C:\windows\system32\python>>import tensorflow as tf >>print(tf.__version__) #to check if tensorflow installed successfully and is accessible
  1. To access TensorFlow through VS code, you need to install python extension for VS code post installing VS code in your system. After successful installation of extension, you can click on "Create new Jupyter notebook" and select the appropriate Python interpreter as in Anaconda.

Now the VS code is ready to run TensorFlow code.
Please check this link for your reference.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文