CentOS7安装IPython notebook

IPython是Python的交互式Shell,提供了代码补完功能、自动缩进、高亮显示、执行Shell命令等非常有用的特性。下面介绍一下在CentOS系统下IPython的安装及一些可能碰到的问题。 
  1.Python的版本及其升级 
IPython安装要求Python版本在2.7及其以上,目前CentOS 7自带的Python版本为2.7.5不需要升级,在其它版本下是需要升级的,目前网上有很多升级Python版本的帖子,基本都能实现。 
查看系统Python版本的命令:

#python --version

  2.IPython的安装 
安装IPython方法有多种,在这里主要介绍pip安装的方法。 
首先下载pip源码 
下载pip到/usr/local/src

# cd /usr/local/src
# wget "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb" 

  解压安装pip

# tar -xzvf pip-1.5.4.tar.gz
# cd pip-1.5.4
# python setup.py install

  更新pip

# pip install --upgrade pip

  安装ipython

# pip install ipython

  注意

centos7 解决 Python.h:没有那个文件或目录 错误的方法

sudo yum install python-devel

安装notebook

# pip intsall notebook

 

如果在启动的时候提示,说明默认不建议使用root来运行,不过我们可以配置文件修改,接下来会介绍如何修改;

  1. [C 15:03:06.778 NotebookApp] Running as root is not recommended. Use --allow-root to bypass.  
 在上一次的版本中直接执行jupyter notebook --generate-config即可初始化配置文件来,但是新版的要加入--allow-root才行;
  1. [root@pydev ~]# jupyter notebook --generate-config --allow-root 
  2. Writing default config to: /root/.jupyter/jupyter_notebook_config.py  
 

创建一个密码:[这样就不用每次复制URL地址] 

  1. [root@jupyter ~]# ipython  
  2. Python 2.7.5 (default, Nov  6 2016, 00:28:07)   
  3. Type "copyright", "credits" or "license" for more information.  
  4.   
  5. IPython 5.3.0 -- An enhanced Interactive Python.  
  6. ?         -> Introduction and overview of IPython's features.  
  7. %quickref -> Quick reference.  
  8. help      -> Python's own help system.  
  9. object?   -> Details about 'object', use 'object??' for extra details.  
  10.   
  11. In [1]: from notebook.auth import passwd  
  12.   
  13. In [2]: passwd()  
  14. Enter password:   
  15. Verify password:   
  16. Out[2]: 'sha1:da874cad4309:4104089e5ef97c8fcbe69c2ac7d6a1071ca50a40' 
 
 修改配置文件中的IP地址、工作目录、并添加一个认证密码:
  1.  #c.NotebookApp.allow_root = False  
  2. 去掉62行的注释,并修改成True即可解决root权限运行的问题。  
  3.  #c.NotebookApp.ip = 'localhost'  
  4. 去掉注释,并把localhost改成0.0.0.0,这样就可以外部访问了,默认只有在本机可以访问的;  
  5.  c.NotebookApp.ip = '0.0.0.0'  
  6.   
  7.  #c.NotebookApp.notebook_dir = u''  
  8. 改成如下,这样就会默认把notebook上创建的文件保存到指定目录下;需要事先创建。   
  9.  c.NotebookApp.notebook_dir = u'/opt/jupyter'  
  10.   
  11.   
  12.  #c.NotebookApp.password = u''  
  13. 加入上面创建的密码:  
  14. c.NotebookApp.password = u'sha1:da874cad4309:4104089e5ef97c8fcbe69c2ac7d6a1071ca50a40'  
 
这里就是行号有所变化;根据关键字查询即可;

保存,重新运行程序:

关闭防火墙:

  1. systemctl stop firewalld && systemctl disable firewalld 

禁用SELINUX:

  1. [root@jupyter ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config 
  2. [root@jupyter ~]# setenforce 0 

 

 参考   https://www.58jb.com/html/146.html

原文地址:https://www.cnblogs.com/heitaoq/p/8527980.html