由于初次使用tensorflow,GPU版本需要安装cuda,cudnn等,太复杂,因此先安装cpu版的,最为最初的尝试,随着对tensorflow了解更多,后续可以尝试安装Tensorflow-GPU.
Fatal error in launcher: Unable to create process using '"c:……‘
此时需要强制升级pip,使用下列命令即可:
python -m pip install --upgrade --force-reinstall tensorflow
还可以升级tensorflow:
pip install --upgrade --force-reinstall tensorflow
查看tensorflow的版本:
tf.__version__
pip成功之后,import tensorflow as tf 报错
Traceback (most recent call last):
File "C:\mysoft\Python\Python35\lib\site-packages\tensorflow\python\platform\self_check.py", line 47, in preload_check
ctypes.WinDLL(build_info.msvcp_dll_name)
File "C:\mysoft\Python\Python35\lib\ctypes\__init__.py", line 347, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] 找不到指定的模块。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
import tensorflow
File "C:\mysoft\Python\Python35\lib\site-packages\tensorflow\__init__.py", line 24, in
from tensorflow.python import *
File "C:\mysoft\Python\Python35\lib\site-packages\tensorflow\python\__init__.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "C:\mysoft\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 30, in
self_check.preload_check()
File "C:\mysoft\Python\Python35\lib\site-packages\tensorflow\python\platform\self_check.py", line 55, in preload_check
% build_info.msvcp_dll_name)
ImportError: Could not find 'msvcp140.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. You may install this DLL by downloading Visual C++ 2015 Redistributable Update 3 from this URL: https://www.microsoft.com/en-us/download/details.aspx?id=53587
其中,
ImportError: Could not find 'msvcp140.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. You may install this DLL by downloading Visual C++ 2015 Redistributable Update 3 from this URL: https://www.microsoft.com/en-us/download/details.aspx?id=53587
原因:缺少VC++ 2015.
解决方法:安装vc++2015, URL:后面的即为下载vc++2015的地址,复制该链接,即可下载,大约14M,下载之后,安装即可,bingo!!
ps:(安装非常简单,1min不到,我之前因为担心又要安装大程序,迟迟不肯定下载并安装,尝试找其他方法解决,然后并没有找到其他的有效解决方法)
经过上面的步骤,import tensorflow as tf已经不再报错,成功安装,因此进行测试:
import tensorflow as tf
hi = tf.constant('Hello, tensorflow')
sess = tf.Session()
这个时候,出现了个warning:
I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
查了资料,说这个问题warning不影响正常运行,可以忽略不计,但是还是想把这个问题解决。
解决方法:
https://tensorflow.google.cn/tutorials/ 官网?
https://www.jianshu.com/p/2ea7a0632239 五分钟带你入门tensorflow
https://blog.csdn.net/geyunfei_/article/details/78782804 第一个入门demo
https://www.bilibili.com/video/av35974848/?spm_id_from=333.788.videocard.0 tensorflow的一个完整的中文教程,炼数成金的课程