小白学AI | 安装jupyter notebook

今天装了个jupyter notebook看能不能在浏览器里直接写代码,顺便写文档。linux不太会,python也是知道皮毛,所以不是太顺利。以下是中间处理的几个小问题。

环境 centos7 + python 2.7.5

用的是镜像自带的python。

[root@play-crm ~]# hostnamectl
   。。。。
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-1127.el7.x86_64
      Architecture: x86-64
[root@play-crm ~]# python --version
Python 2.7.5

中间遇到了几个坑,记录

错误1:安装工具太老了

Unknown distribution option: 'project_urls'

    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-V_5ggM/send2trash/setup.py'"'"'; __file__='"'"'/tmp/pip-install-V_5ggM/send2trash/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-rvfTY8
         cwd: /tmp/pip-install-V_5ggM/send2trash/
    Complete output (5 lines):
    /usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'long_description_content_type'
      warnings.warn(msg)
    /usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'project_urls'
      warnings.warn(msg)
    error in Send2Trash setup command: 'extras_require' must be a dictionary whose values are strings or lists of strings containing valid project/version requirement specifiers.
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

要升级pip或者setuptools: https://github.com/gevent/gevent/issues/1646
直接运行
pip install -U pip setuptools

错误2:启动报错 UnicodeDecodeError

[root@play-crm ~]# jupyter notebook
The Jupyter HTML Notebook.

这将启动一个基于tornado的HTML笔记本服务器,它提供一个html5/
javascript笔记本客户端。

Traceback (most recent call last):
  File "/usr/bin/jupyter-notebook", line 8, in <module>
    sys.exit(main())
  File "/usr/lib/python2.7/site-packages/jupyter_core/application.py", line 270,       in launch_instance
    return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
  File "/usr/lib/python2.7/site-packages/traitlets/config/application.py", line       663, in launch_instance
    app.initialize(argv)
  File "<string>", line 2, in initialize
  File "/usr/lib/python2.7/site-packages/traitlets/config/application.py", line       89, in catch_config_error
    app.print_help()
  File "/usr/lib/python2.7/site-packages/traitlets/config/application.py", line       386, in print_help
    self.print_subcommands()
  File "/usr/lib/python2.7/site-packages/traitlets/config/application.py", line       378, in print_subcommands
    print(os.linesep.join(lines))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 4: ordinal       not in range(128)

使用中文字符集的系统上,python2.7转码会出错

In case any Chinese users would like any actually useful help with this issue, while you should upgrade to using Python 3 versions of Jupyter if possible, if you cannot upgrade for whatever reason: try setting the environment variable LANGUAGE=en_US so that Jupyter doesn't try to use its Chinese translation, which clearly doesn't work well on Python 2
https://github.com/jupyter/notebook/issues/4166

修改系统的默认字符集成en_US.utf8

方法如下:https://www.osetc.com/en/centos-7-rhel-7-change-the-system-locale.html

  1. 确认系统语言环境
[root@play-crm ~]# locale
LANG=zh_CN.UTF-8
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=

  1. 改文件
vi /etc/locale.conf

内容改成

LANG=es_US.utf8
  1. 重启
    reboot

jupyter notebook的启动参数

jupyter notebook --allow-root --password testjupyter --ip 192.168.3.179

  1. --allow-root 允许用root账号启动
    如果你用root来启动,默认不允许,所以加参数
  2. --ip 默认只能用localhost访问

防火墙开端口8888

centos7提供firewall-cmd来设置防火墙,比较简单,两行搞定

参考:https://www.xmodulo.com/open-port-firewall-centos-rhel.html

$ sudo firewall-cmd --zone=public --add-port=8888/tcp --permanent
$ sudo firewall-cmd --reload

搞定收工

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容