Ubuntu18.04LTS下cuda10.0+cudnn7.5+TensorFlow1.13環境搭建python
- 前言
- macOS
- Ubuntu 18.04 LTS
- 最後
這篇是對上一篇的補充, 主要是macOS和Ubuntu下的cpu版的TensorFlow安裝, 總體都比較簡單.linux
在用pip3下載以前, 我建議先修改下Mac的pip鏡像源, 不然下載很糟心.vim
cd ~/
mkdir .pip
cd .pip
touch pip.conf
vim pip.conf
複製代碼
輸入以下內容:bash
[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
複製代碼
可選源還有不少, 可是阿里的足夠了.測試
- http://pypi.douban.com/
- http://pypi.hustunique.com/
- http://pypi.sdutlinux.org/
- http://pypi.mirrors.ustc.edu.cn/
接着安裝下virtualenvui
sudo pip3 install --upgrade virtualenv
virtualenv --system-site-packages ~/tensorflow
cd ~/tensorflow
複製代碼
而後依據本身的bash版本輸入以下指令的一條, 好比我就是zsh, 輸入第一個指令, #號及以後部分都是註釋, 不要輸入:google
source ~/tensorflow/bin/activate # If using bash, sh, ksh, or zsh
source ~/tensorflow/bin/activate.csh # If using csh or tcsh
複製代碼
而後py3.x用第二條, py2.7用第一條:url
pip install --upgrade tensorflow # for Python 2.7
pip3 install --upgrade tensorflow # for Python 3.x
複製代碼
以後想要退出當前環境, 就輸入以下指令:spa
deactivate
複製代碼
大致效果以下圖:code
接下來是一個測試小栗子:
#!/usr/local/bin/python3
import tensorflow as tf
hello = tf.constant('Hello, tf!')
sess = tf.Session()
print (sess.run(hello))
a = tf.constant(10)
b = tf.constant(32)
print (sess.run(a+b))
matrix1 = tf.constant([[3., 3.]])
matrix2 = tf.constant([[2.],[2.]])
product = tf.matmul(matrix1, matrix2)
result = (sess.run(product))
print (result)
sess.close()
複製代碼
可能你們會疑惑一開始的那一段, 能夠加入以下代碼:
# Just disables the warning, doesn't enable AVX/FMA
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
複製代碼
這樣就沒有了, 具體緣由, 自行google咯:
總體操做邏輯差很少, 先改下鏡像源:
apt-get install python-pip python-dev build-essential
pip install --upgrade pip
pip3 install --upgrade virtualenv
複製代碼
而後建立pip.conf文件:
mkdir ~/.pip
vim ~/.pip/pip.conf
複製代碼
添加源:
[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
複製代碼
最後安裝TensorFlow:
pip3 install tensorflow
複製代碼
複製以前的測試案例測試下:
關於GPU版本的, 能夠參看Ubuntu18.04LTS下cuda10.0+cudnn7.5+TensorFlow1.13環境搭建. 喜歡記得點贊哦, 有意見或者建議評論區見~