pycharm配置tensorflow环境 适用于Python3.6 CPU

一、环境

  基于安装Python3.6以及pycharm。

二、在项目设置里配置编译环境

  打开pycharm新建一个项目。

  打开pycharm->file->setting->project:->project interpreter,将自己的interpreter调整到安装的3.6版本,大部分是已经调整好的

三、pip下载TensorFlow

  打开命令行窗口使用pip命令安装TensorFlow,输入

  

pip install tensorflow==1.4

四、测试是否配置成功

  在新建的项目中创建.py文件,运行

 1 import tensorflow as tf
 2 
 3 if __name__ == '__main__':
 4     # 定义两个向量a,b
 5     a = tf.constant([1.0, 2.0], name='a')
 6     b = tf.constant([2.0, 3.0], name='b')
 7     result = a + b
 8     sess = tf.Session()  # 生成一个会话,通过一个会话session来计算结果
 9     # 实现了一个简单的Tensorflow模型
10     print(sess.run(result))

  输出

  [3. 5.]

  Process finished with exit code 0

  则安装成功。

四、安装过程中的一些坑

  1.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

  这是因为安装了gpu版本的TensorFlow,但是电脑本身不支持GPU版本的,只能将GPU和CPU两个版本(pip的时候TensorFlow 和TensorFlow-GPU)全部卸载。然后重新只装CPU版的。

原文地址:https://www.cnblogs.com/youyou0/p/9509453.html