人工智能实践入门-Day0小鱼安装Tensorflow之各种报错踩坑及全面解决方法

之前已经安装了python3.7和pycharm,没装anaconda和tensorflow,第一次安装tensorflow没有经验,各种报错,哭了。。也没有人可以问,笨手笨脚踩了无数坑555,自己通过搜索倒腾了一天终于解决了所有问题,谨写此文希望能帮到和我一样的小白。。。大佬不要笑我

一、安装平台

在这里插入图片描述
windows10系统64位

二、目标环境

  • Anaconda 3
  • python 3.6
  • pycharm 2019.3
  • tensorflow 2.0.0

三、安装过程报错解决过程

1、activate tensorflow成功,install失败解决方法:
注意python与tensorflow版本匹配问题,查询anaconda内置python版本修改install命令。

2、报错’conda’ 不是内部或外部命令,也不是可运行的程序或批处理文件。
解决方法链接
在这里插入图片描述
添加路径:C:\Users\yuqia\Anaconda3C:\Users\yuqia\Anaconda3\Scripts

3.安装过程报错ERROR: Exception: Traceback (most recent call last): File "c:\users\yuqia\anaconda3\lib\site-packa…
在这里插入图片描述
解决方法链接
注意区分cpu版和gpu版安装方式,install命令中修改pip为pip3

4.再次报错可能是网速问题,解决方法,指定镜像源下载
解决方法链接

5.还报错,新的Error解决方法:pip检查,pip3
在这里插入图片描述
6、下载顺利,但快结束又报错了
在这里插入图片描述
解决方法链接

7.tensorflow安装好后报错ImportError: DLL load failed: 找不到指定的模块。
Failed to load the native TensorFlow runtime. See https://www.tensorflow.org/install/errors for some common reasons and solutions. Include the entire stack trace above this error message when asking for help.
解决方法链接

8、还是不行,哭了,可能是版本不匹配,再试一个方法:
解决方法链接
之前默认安装的tensorflow最新版本2.2.0,现在指定安装2.0.0报错。。。

9.嗯,又是网速问题?
解决方法链接
用这个镜像源命令安装试试8:

pip3 install tensorflow==2.0.0 -i https://pypi.douban.com/simple

终于好啦~

10.装上了,导入试试:
检测方法链接

检测方法:

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

输入第二行时报错:

2020-05-23 12:13:02.543110: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

这个问题不大,可以忽略,不影响使用,强迫症也可以按以下解决解决方法:解决方法链接

11、继续检测,输入到第三行报错:

AttributeError: module 'tensorflow' has no attribute 'Session'

原来tensorflow2.0和旧版本不一样!!不能按旧版本命令测试解决方法:添加链接描述

这样检测试试:

>>> import tensorflow as tf
>>> hello=tf.constant('hello,tensorflow')
>>> sess=tf.compat.v1.Session()
>>> print(sess.run(hello))

12、再来!前三行没有问题,输入到第四行报错:

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

解决方法:方法1
不太对,换一个:方法2
应该用这个测试:

>>> import tensorflow as tf
>>>
>>> g = tf.Graph()
>>> with g.as_default():
...     one = tf.constant([[3,3]])
...     two = tf.constant([[2],[2]])
...     p = tf.matmul(one,two)
...     sess = tf.compat.v1.Session(graph=g)
...     re=sess.run(p)
...     print(re)

输出

[[12]]

测试完成,OKK,已累瘫

13、Anaconda prompt装好了tensorflow如何导入pycharm?
方法链接
看一下python路径:方法

>>> import sys
>>> print(sys.path)

输出

['', 'C:\\Users\\yuqia\\Anaconda3\\python36.zip', 'C:\\Users\\yuqia\\Anaconda3\\DLLs', 'C:\\Users\\yuqia\\Anaconda3\\lib', 'C:\\Users\\yuqia\\Anaconda3', 'C:\\Users\\yuqia\\Anaconda3\\lib\\site-packages', 'C:\\Users\\yuqia\\Anaconda3\\lib\\site-packages\\win32', 'C:\\Users\\yuqia\\Anaconda3\\lib\\site-packages\\win32\\lib', 'C:\\Users\\yuqia\\Anaconda3\\lib\\site-packages\\Pythonwin']

选择这个路径下的python在pycharm中测试
在这里插入图片描述
OKK!!

14.用了几天新出现
import tensorflow as tf报错:TypeError: expected bytes, Descriptor found
在这里插入图片描述

看了下tensorflow下python怎么是3.7.7???我明明装的3.6.。。可能是因为我装anaconda之前装过python3.7.7…
解决方法:先把3.7.7的python卸载,再把anaconda卸载重装…
今天按这个教程重装了一次anaconda和tensorflow:
https://blog.csdn.net/PursueWin/article/details/97563574?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522159159468219725211913678%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=159159468219725211913678&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_ecpm_v3~pc_rank_v2-1-97563574.first_rank_ecpm_v3_pc_rank_v2&utm_term=anaconda+tensorflow%E5%AE%89%E8%A3%85+pycharm

15、安装报错ERROR: Cannot unpack file C:…cannot detect archive format ERROR: Cannot determine archive format of C:\Users\yuqia\AppData\Local\Temp\pip-req-build-bb6i9iua
解决方案:
https://blog.csdn.net/CHQC388/article/details/104839877?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522159160182219195239849635%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=159160182219195239849635&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_ecpm_v1~rank_ctr_v2-2-104839877.ecpm_v1_rank_ctr_v2&utm_term=+ERROR%3A+Cannot+unpack+file+C%3A%5C
一个没解决。。。改用以前的命令

pip3 install tensorflow==2.0.0 -i https://pypi.douban.com/simple

OKK!

16、一个小问题:Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
cpu太菜啦,忽略,解决方法:

import os
>>> # os.environ["TF_CPP_MIN_LOG_LEVEL"]='1' # 这是默认的显示等级,显示所有信息
... os.environ["TF_CPP_MIN_LOG_LEVEL"]='2' # 只显示 warning 和 Error
>>> # os.environ["TF_CPP_MIN_LOG_LEVEL"]='3' # 只显示 Error

导入pycharm测试

import tensorflow as tf
tensorflow_version=tf.__version__
print("tensorflow version",tensorflow_version)
a=tf.constant([1.0,2.0],name='a')
b=tf.constant([1.0,2.0],name='b')
result=tf.add(a,b,name='add')
print(result)

输出

tensorflow version 2.0.0
tf.Tensor([2. 4.], shape=(2,), dtype=float32)

OKK!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章