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版的。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM