#问题及解决方案整理# | python | anaconda+TensorFlow软件安装运行中的各种问题(已成功解决)

#问题及解决方案整理# | python | anaconda+TensorFlow软件安装运行中的各种问题(已成功解决)

背景

运行环境:Windows 10,anaconda,python3.9.7,TensorFlow
[TencentCloudSDKException] code:InvalidParameter.MissingParameter message:Check whether the parameters are carried or empty requestId:1135a103-cd70-4b11-9671-8c8c41139a43

[En]

常用指令

查看conda的版本

conda --version

#问题及解决方案整理# | python | anaconda+TensorFlow软件安装运行中的各种问题(已成功解决)

查看python的版本

python

#问题及解决方案整理# | python | anaconda+TensorFlow软件安装运行中的各种问题(已成功解决)

查看anaconda安装了哪些环境变量

conda info --envs

原因及解决方案:

在安装完成anaconda环境后,在anaconda prompt下安装tensorflow。于是出现了上述问题。
根据原因分析,下载安装包的图像源没有连接,需要更换下载源链接。

[En]

According to the analysis of the reason, the image source for downloading the installation package is not connected, and the download source link needs to be replaced.

参考1-11-2

  • 直接打开本地电脑上对应路径 C:\Users\Jing下的文件 .condarc,打开方式为记事本就行。此处路径中的 Jing对应为自己的电脑的用户名称。
  • 修改文件内容,如下所示:
    [En]

    modify the contents of the file as shown below:*

    #问题及解决方案整理# | python | anaconda+TensorFlow软件安装运行中的各种问题(已成功解决)
    删掉默认 - deault,添加几行清华镜像地址。
  • 您不仅可以通过文件夹添加镜像地址,还可以通过命令行执行来添加。命令行如下所示:
    [En]

    you can add an image address not only through a folder, but also by executing on the command line. The command line reads as follows:*

  • 保存并重新启动计算机(这一步很关键!)
    [En]

    Save off and restart the computer (this step is critical! ).*

  • 重新激活tensflow的环境变量 activate py39
  • 执行安装命令 pip install --upgrade --ignore-installed tensorflow
  • 通过命令行启动 Spyder

; 问题2:moduleNotFoundError:No module named ‘tensorflow’

#问题及解决方案整理# | python | anaconda+TensorFlow软件安装运行中的各种问题(已成功解决)

原因及解决方案:

安装完成anaconda环境后,在anaconda prompt下安装tensorflow,命令运行成功了,但是直接在”开始”列表中点击 Spyder,然后进入Spyder的开发环境。运行自己的程序,出现上述问题,显示没有tensorflow模块。

在互联网上查找大量的信息和文章有几个原因。

[En]

Look up a lot of information and articles on the Internet for several reasons.

原因1:python和tensor版本不一致。

原因2:确实就是没有安装tensorflow。

原因3:python运行环境中没有配置好tensorflow,没有在tensorflow的环境下打开它们。
参考2-1

  • 我们需要在tensorflow的环境中安装ipython 和Spyder两个插件。
  • 打开 Anaconda Navigator,选择 Not installed,找到 ipythonSpyder并安装 installapply
  • 重新在正确打开的Spyder环境中运行程序,即可以正常执行,问题解决。

问题3:AttributeError: module ‘tensorflow’ has no attribute ‘Session’

原因及解决方案:

在安装完成TensorFlow后,需要验证环境是否安装成功,所以使用示例程序,看是否能运行成功,于是出现了该问题的错误。
因为在新的Tensorflow 2.0版本中已经移除了Session这一模块,改换运行代码。
示例代码如下:

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

参考3-1后:

  • 改出错的那一行 tf.Session()的代码为 tf.compat.v1.Session(),运行,问题解决。

问题4:RuntimeError: The Session graph is empty. Add operations to the graph before calling run().

原因及解决方案:

在安装完成TensorFlow后,需要验证环境是否安装成功,所以使用示例程序,看是否能运行成功,于是出现了该问题的错误。
示例代码如下:

import tensorflow as tf

hello = tf.constant('hello,tensorflow')
sess= tf.compat.v1.Session() #版本2.0的函数,这里也得注意
print(sess.run(hello))

参考4-1后:

  • 加上这一行 tf.compat.v1.disable_eager_execution() ,运行代码,问题解决。

问题5:you have missing dependencies Spyder: You have missing dependencies! #Mandatory: nbconvert>=4.0

现象

#问题及解决方案整理# | python | anaconda+TensorFlow软件安装运行中的各种问题(已成功解决)

; 原因及解决方案:

参考5-1后:

  • 在Spyder菜单栏选择Help–>Dependencies可以查看当前安装版本的依赖包及各自安装情况:可以看到确实少了这个包的依赖。
    #问题及解决方案整理# | python | anaconda+TensorFlow软件安装运行中的各种问题(已成功解决)
  • 用conda list查看包情况:就在那里,列表中有该包。
    #问题及解决方案整理# | python | anaconda+TensorFlow软件安装运行中的各种问题(已成功解决)
    #问题及解决方案整理# | python | anaconda+TensorFlow软件安装运行中的各种问题(已成功解决)
  • 重新在命令行中的py39环境(改为自己创建的环境变量即可)下,输入 Spyder进入开发环境:发现没有报错了;
    #问题及解决方案整理# | python | anaconda+TensorFlow软件安装运行中的各种问题(已成功解决)
  • 查看help的依赖包,对应的包已经有了 ,问题解决。
    #问题及解决方案整理# | python | anaconda+TensorFlow软件安装运行中的各种问题(已成功解决)

; 问题6:ModuleNotFoundError: No module named ‘PIL’

原因及解决方案:

参考6-1

  • 退出Spyder;在命令行输入 pip install Pillow
    #问题及解决方案整理# | python | anaconda+TensorFlow软件安装运行中的各种问题(已成功解决)
  • 再次通过命令行 Spyder进入环境,运行代码,问题解决。

; 问题7:ModuleNotFoundError: No module named ‘matplotlib’

现象

#问题及解决方案整理# | python | anaconda+TensorFlow软件安装运行中的各种问题(已成功解决)

; 原因及解决方案:

参考7-1

  • 退出Spyder;在命令行输入 pip install matplotlib
    #问题及解决方案整理# | python | anaconda+TensorFlow软件安装运行中的各种问题(已成功解决)
  • 再次通过命令行 Spyder进入环境,运行代码,问题解决。

Original: https://blog.csdn.net/qq_41921189/article/details/123966135
Author: 进阶中的小太阳
Title: #问题及解决方案整理# | python | anaconda+TensorFlow软件安装运行中的各种问题(已成功解决)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/496675/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球