1. 程式人生 > >centos7安裝 jupyter

centos7安裝 jupyter

Jupyter Notebook(此前被稱為 IPython notebook)是一個互動式筆記本,支援執行 40 多種程式語言。

Jupyter Notebook 的本質是一個 Web 應用程式,便於建立和共享文學化程式文件,支援實時程式碼,數學方程,視覺化和 markdown。 用途包括:資料清理和轉換,數值模擬,統計建模,機器學習等等

-------- 來至百度百科

系統:

centos7

centos7預設是python2,依照官網進行安裝

# python -m pip install --upgrade pip

# python -m pip install jupyter

提示出錯:

Downloading 

setuptools-40.4.3-py2.py3-none-any.whl (569kB)

wheel-0.32.1-py2.py3-none-any.whl

ipython-7.0.1.tar.gz (5.1MB)

Complete output from command python setup.py egg_info:

      IPython 7.0+ supports Python 3.5 and above.

      When using Python 2.7, please install IPython 5.x LTS Long Term Support version.

      Python 3.3 and 3.4 were supported up to IPython 6.x.

      See IPython `README.rst` file for more information:

          https://github.com/ipython/ipython/blob/master/README.rst

      Python sys.version_info(major=2, minor=7, micro=5, releaselevel='final', serial=0) detected.

可以看到,下載的ipython最少需要python3.3的支援

編譯python3

安裝依賴

# yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

備份

# cd /usr/bin

# mv python python.bak

下載並編譯

# wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz

# tar -xvJf  Python-3.6.2.tar.xz

# cd Python-3.6.2

# ./configure prefix=/usr/local/python3

# make && make install

# ln -s /usr/local/python3/bin/python3 /usr/bin/python

驗證,同時存在python2和python3

# python -V

Python 3.6.2

# python2 -V

Python 2.7.5

編輯yum和urlgrabber-ext-down

執行yum需要python2,需要修改yum的配置

# vi /usr/bin/yum

#! /usr/bin/python

>>

#! /usr/bin/python2

# vi /usr/libexec/urlgrabber-ext-down

#! /usr/bin/python

>> 

#! /usr/bin/python2

依照官網進行安裝

# python3 -m pip install --upgrade pip

# python3 -m pip install jupyter

Successfully installed MarkupSafe-1.0 Send2Trash-1.5.0 backcall-0.1.0 bleach-3.0.0 decorator-4.3.0 defusedxml-0.5.0 entrypoints-0.2.3 ipykernel-5.0.0 ipython-7.0.1 ipython-genutils-0.2.0 ipywidgets-7.4.2 jedi-0.13.1 jinja2-2.10 jsonschema-2.6.0 jupyter-1.0.0 jupyter-client-5.2.3 jupyter-console-6.0.0 jupyter-core-4.4.0 mistune-0.8.3 nbconvert-5.4.0 nbformat-4.4.0 notebook-5.7.0 pandocfilters-1.4.2 parso-0.3.1 pexpect-4.6.0 pickleshare-0.7.5 prometheus-client-0.4.0 prompt-toolkit-2.0.5 ptyprocess-0.6.0 pygments-2.2.0 python-dateutil-2.7.3 pyzmq-17.1.2 qtconsole-4.4.1 simplegeneric-0.8.1 six-1.11.0 terminado-0.8.1 testpath-0.4.2 tornado-5.1.1 traitlets-4.3.2 wcwidth-0.1.7 webencodings-0.5.1 widgetsnbextension-3.4.2

生成配置檔案

# jupyter notebook --generate-config

Writing default config to: /root/.jupyter/jupyter_notebook_config.py

生成密碼

# python3

Python 3.6.2 (default, Nov  2 2018, 16:17:04)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-28.0.1)] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> from notebook.auth import passwd

>>> passwd()

此時會讓你兩次輸入密碼,然後就會生成祕鑰

修改配置檔案

# vi ~/.jupyter/jupyter_notebook_config.py

# 設定所有IP皆可訪問

c.NotebookApp.ip = '0.0.0.0'

c.NotebookApp.password = u'生成的金鑰'

# 禁止自動開啟瀏覽器

c.NotebookApp.open_browser = Flase

# 服務埠

c.NotebookApp.port = 8080

這裡需要注意的是c.NotebookApp.ip,這個配置項如果按照網上大多數的配置配置為*的話,就會出現下面的錯誤:

# jupyter notebook

[I 16:54:09.881 NotebookApp] Writing notebook server cookie secret to /run/user/13011/jupyter/notebook_cookie_secret

Traceback (most recent call last):

  File "/usr/local/lib/python3.6/site-packages/traitlets/traitlets.py", line 528, in get

    value = obj._trait_values[self.name]

KeyError: 'allow_remote_access'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "/usr/local/lib/python3.6/site-packages/notebook/notebookapp.py", line 869, in _default_allow_remote

    addr = ipaddress.ip_address(self.ip)

  File "/usr/local/lib/python3.6/ipaddress.py", line 54, in ip_address

    address)

ValueError: '' does not appear to be an IPv4 or IPv6 address

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "/usr/local/bin/jupyter-notebook", line 11, in <module>

    sys.exit(main())

  File "/usr/local/lib/python3.6/site-packages/jupyter_core/application.py", line 266, in launch_instance

    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)

  File "/usr/local/lib/python3.6/site-packages/traitlets/config/application.py", line 657, in launch_instance

    app.initialize(argv)

  File "<decorator-gen-7>", line 2, in initialize

  File "/usr/local/lib/python3.6/site-packages/traitlets/config/application.py", line 87, in catch_config_error

    return method(app, *args, **kwargs)

  File "/usr/local/lib/python3.6/site-packages/notebook/notebookapp.py", line 1629, in initialize

    self.init_webapp()

  File "/usr/local/lib/python3.6/site-packages/notebook/notebookapp.py", line 1379, in init_webapp

    self.jinja_environment_options,

  File "/usr/local/lib/python3.6/site-packages/notebook/notebookapp.py", line 158, in __init__

    default_url, settings_overrides, jinja_env_options)

  File "/usr/local/lib/python3.6/site-packages/notebook/notebookapp.py", line 251, in init_settings

    allow_remote_access=jupyter_app.allow_remote_access,

  File "/usr/local/lib/python3.6/site-packages/traitlets/traitlets.py", line 556, in __get__

    return self.get(obj, cls)

  File "/usr/local/lib/python3.6/site-packages/traitlets/traitlets.py", line 535, in get

    value = self._validate(obj, dynamic_default())

  File "/usr/local/lib/python3.6/site-packages/notebook/notebookapp.py", line 872, in _default_allow_remote

    for info in socket.getaddrinfo(self.ip, self.port, 0, socket.SOCK_STREAM):

  File "/usr/local/lib/python3.6/socket.py", line 743, in getaddrinfo

    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):

socket.gaierror: [Errno -2] Name or service not known

需要注意版本資訊,如果notebook為5.6.0以下版本,c.NotebookApp.ip = '*',為以上版本,則設定為c.NotebookApp.ip = '0.0.0.0'

啟動服務

# jupyter notebook

[C 17:02:44.143 NotebookApp] Running as root is not recommended. Use --allow-root to bypass.

根據提示使用root使用者啟動需要加入引數

# jupyter notebook --allow-root

[I 17:04:12.761 NotebookApp] Serving notebooks from local directory: /home/sphuser/Python-3.6.2

[I 17:04:12.761 NotebookApp] The Jupyter Notebook is running at:

[I 17:04:12.761 NotebookApp] http://(jupyterserver or 127.0.0.1):8080/

[I 17:04:12.761 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

開啟 IP:指定的埠, 輸入密碼就可以訪問了

參考文件:

http://jupyter.org/install.html

https://www.cnblogs.com/JahanGu/p/7452527.html

https://blog.csdn.net/qq_18293213/article/details/72910834

https://my.oschina.net/mengyoufengyu/blog/2252687