xinhu1300 发表于 2019-2-15 15:29:52

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 -xvJfPython-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, Nov2 2018, 16:17:04)
   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
   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
  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
  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 "", 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: Name or service not known
  需要注意版本信息,如果notebook为5.6.0以下版本,c.NotebookApp.ip = '*',为以上版本,则设置为c.NotebookApp.ip = '0.0.0.0'
  启动服务
  # jupyter notebook
   Running as root is not recommended. Use --allow-root to bypass.
  根据提示使用root用户启动需要加入参数
  # jupyter notebook --allow-root
   Serving notebooks from local directory: /home/sphuser/Python-3.6.2
   The Jupyter Notebook is running at:
   http://(jupyterserver or 127.0.0.1):8080/
   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



页: [1]
查看完整版本: centos7安装 jupyter