---
# System prepended metadata

title: 3.TensorFlow + Keras 的第一步
tags: [人工智慧]

---

###### tags: `人工智慧`

# 3.TensorFlow + Keras 的第一步

新手開始安裝(Windows)
===

#### 建立 trnsorflow anaconda虛擬環境
```
conda create --name tensorflowAI python=3.5 anaconda
```


#### 啟動 anaconda虛擬環境
```
activate tensorflowAI
```

#### 關閉 anaconda虛擬環境
```
deactivate tensorflowAI
```
---
#### 安裝 tensorflow CPU
```
pip install tensorflow
```

:::info
:mega: 出現錯誤
ERROR: Cannot uninstall 'wrapt'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

```
pip install -U --ignore-installed wrapt enum34 simplejson netaddr
```

:mega: python版本與anaconda虛擬環境不一樣
```
conda install tensorflow
```
:::

#### 安裝 keras
```
pip install keras
```
:::info
:mega: python版本與anaconda虛擬環境不一樣
```
conda install keras
```
:::

---

#### 啟動jupyter
```
activate tensorflowAI
jupyter notebook
```

#### 讓jupyter更好用
[jupyter themes](https://www.796t.com/article.php?id=18214)
[Jupyter extend](https://zhuanlan.zhihu.com/p/35430879)
[jupyter 補字](https://www.796t.com/article.php?id=217867)
[補](https://github.com/codota/jupyter-tabnine)
:::info
:mega: pip沒反應可以試試conda
```
conda install -c conda-forge jupyter_nbextensions_configurator
conda install -c conda-forge jupyter_contrib_nbextensions
jupyter nbextensions_configurator enable --user
jupyter contrib nbextension install --user

jt -t oceans16 -f fira -fs 18 -cellw 99% -tfs 20 -dfs 16 -ofs 16 -lineh 170 -T -N -kl
```
:::
[](https://chrislee0728.medium.com/%E4%BA%94%E5%80%8B%E5%A5%BD%E7%94%A8%E7%9A%84-jupyter-notebook-%E6%8F%92%E4%BB%B6-e391b82638d5)
---

新手開始安裝(Linux)
===

#### [anaconda下載](https://www.anaconda.com/products/individual#Downloads)
```
wget https://repo.anaconda.com/archive/Anaconda3-2021.05-Linux-x86_64.sh
```

#### 安裝anaconda
```
bash Anaconda3-2021.05-Linux-x86_64.sh -b
sudo gedit ~/ .bashrc
export PATH="/home/user/anaconda3/bin:$PATH"
source ~/.bashrc
python --version
```
:notebook: -b batch 是批次安裝
 
#### anaconda加到PATH
```
sudo gedit ~/ .bashrc

export PATH="/home/user/anaconda3/bin:$PATH"
```

#### 重新登入
```
source ~/.bashrc
```

#### 確定版本
```
python --version
```

---
####  安裝 tensorflow CPU
```
pip install tensorflow
```

####  安裝 keras
```
pip install keras
```

---

#### 啟動jupyter
```
mkdir -p ~/pywork
cd ~/pywork

jupyter notebook
```
---

# 更方便使用 anacond 跟 jupyter

#### Step 1. 安裝[Windows terminal](https://www.microsoft.com/store/productId/9N0DX20HK701)

#### Step 2. 搜尋anacond > 右鍵開啟檔案位置

![](https://i.imgur.com/Gkz4C7Y.png)

#### Step 3. 在anacond右鍵開起屬性 > 複製Target

![](https://i.imgur.com/8zhXtU7.png)

#### Step 4. 開啟Windows terminal 設定

![](https://i.imgur.com/7ljKTAS.png)

#### Step 5. 新增一個新的

![](https://i.imgur.com/DAuTEQH.png)

---

#### Step 6. 修改設定檔

+ 名稱可以任意取

+ 將複製的Target貼到命令列
```
%windir%\System32\cmd.exe "/K"
C:\Users\55614\anaconda3\Scripts\activate.bat 
C:\Users\55614\anaconda3\envs\tensorflow35
```

+ 刪除/修改Target一些內容

```
cmd.exe /K 
C:\Users\55614\anaconda3\Scripts\activate.bat 
C:\Users\55614\anaconda3\envs\tensorflow35
```

+ 圖示
```
C:\Users\55614\anaconda3\Menu\anaconda-navigator.ico
```
[guid]::NewGuid()
+ 如圖
![](https://i.imgur.com/fHhcAh2.png)

#### 新增jupyter

也一樣重複 Step 2.
![](https://i.imgur.com/wt1Ijgy.png)

---

#### 完成就可以直接呼叫了
![](https://i.imgur.com/Y8cw4Dt.png)






