之前已經安裝了python3.7和pycharm,沒裝anaconda和tensorflow,第一次安裝tensorflow沒有經驗,各種報錯,哭了。。也沒有人可以問,笨手笨腳踩了無數坑555,自己通過搜索倒騰了一天終於解決了所有問題,謹寫此文希望能幫到和我一樣的小白。。。大佬不要笑我
Tensorflow安裝日記--目錄
一、安裝平臺
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().
>>> 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!