Centos 7.4 安裝 Jupyter NoteBook + TensorFlow 教程

open_jupyter_notebook.png

前言

這幾天看學習視頻,看到一個很好玩的東西 Jupyter Notebook,可是視頻上面都是安裝的本地的。因而乎我想着,本身買的服務器閒着也是閒着就拿出來裝一個,這樣的話能夠「雲」使用。前端

0. 安裝篇

這裏我就直接使用 pyenv 的虛擬環境去安裝,以前我有寫過 Centos 7.4 安裝 pyenv,以及虛擬環境的使用。不知道的你們能夠去看一下這篇文章《Centos 7.4 多版本Python以及虛擬環境安裝》python

先建立一個虛擬環境瀏覽器

建立一個 Python v3.6.9 的虛擬環境,並進入環境。直接上命令吧:bash

# 建立
pyenv virtualenv 3.6.9 Jupyter_3.6

# 進入
pyenv activate Jupyter_3.6

接着就是簡單粗暴的安裝:服務器

pip install ipython

pip install jupyter

其實到這裏安裝環節應該說是差很少了,可是要運行起來還須要配置一下。post

下面放一下安裝截圖:學習

ipython 安裝spa

ipython安裝結果

jupyter 安裝插件

jupyter安裝結果

1. 配置篇

生成配置文件code

# 若是是root用戶要加 --allow-root (我用的 root )
jupyter notebook --generate-config --allow-root

這裏再使用 ipython 生成一下祕鑰:

# 進入 ipython
ipython

# 這個是進入 ipython 後系統輸出的
Python 3.6.9 (default, Aug  8 2019, 17:18:19)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.7.0 -- An enhanced Interactive Python. Type '?' for help.

# In 是輸入,Out 是輸出
# 引包
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
# 記住這個祕鑰
Out[2]: 'sha1:5d8d5d6ea2a5:04a*************************3c24b7280b67'
# 退出
In [3]: exit()

下面修改配置文件:

# 對外提供訪問的ip
c.NotebookApp.ip = '0.0.0.0'
# 對外提供訪問的端口
c.NotebookApp.port = 37197
# 啓動不打開瀏覽器
c.NotebookApp.open_browser = False
# 上面生成的祕鑰
c.NotebookApp.password = 'sha1:5d8d5d6ea2a5:04a*************************3c24b7280b67'
# 設置jupyter啓動後默認文件夾
c.NotebookApp.notebook_dir = u'/root/jupyter/jupyter_dir'
# 容許root用戶執行
c.NotebookApp.allow_root = True

安裝插件、使用主題

pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
pip install jupyterthemes  # 安裝
jt -t chesterish  # 使用chesterish主題(可能須要重啓jupyter)
jt -r  # 恢復默認主題

運行

jupyter notebook

已經正常運行,能夠打開服務器的 IP:PORT 就能夠看到運行效果啦:

而後登陸的話就是剛剛咱們設置的密碼,固然不是祕鑰啦,是變成祕鑰前輸入了兩次那個密碼。
右上角那裏有個 New 建立一個新文件,而後選 Python 3 啦。

到這裏安裝已經完成啦,安心食用吧!

後臺運行

可是你會發現這樣不能夠後臺運行,退出之後就訪問不了了。
這個時候一條命令就能夠幫你解決問題。

# cofing 後面對應的剛開始的那個配置文件
nohup jupyter notebook --config=/root/.jupyter/jupyter_notebook_config.py  > /dev/null 2>&1 &

2. TensorFlow 安裝篇

這個就比較簡單了

pip install tensorflow

我機器上裝完之後會有報錯,報錯信息以下:

FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy

找了一些資料好像說是 numpy 版本太高的問題。因而乎下卸載,再安裝一個低版本。

pip uninstall numpy
pip install numpy==1.1.3

這樣個人 Centos 7.4 上就能夠運行啦,能夠看到版本號是 1.3.0!

拒絕拖延(感謝關注)

公衆號:前端曰

公衆號ID:js-say

ps:是(yuē)不是(ri)

相關文章
相關標籤/搜索