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来运行,不过我们可以配置文件修改,接下来会介绍如何修改;
- [C 15:03:06.778 NotebookApp] Running as root is not recommended. Use --allow-root to bypass.
在上一次的版本中直接执行jupyter notebook --generate-config即可初始化配置文件来,但是新版的要加入--allow-root才行;
- [root@pydev ~]# jupyter notebook --generate-config --allow-root
- Writing default config to: /root/.jupyter/jupyter_notebook_config.py
创建一个密码:[这样就不用每次复制URL地址]
- [root@jupyter ~]# ipython
- Python 2.7.5 (default, Nov 6 2016, 00:28:07)
- Type "copyright", "credits" or "license" for more information.
- IPython 5.3.0 -- An enhanced Interactive Python.
- ? -> Introduction and overview of IPython's features.
- %quickref -> Quick reference.
- help -> Python's own help system.
- object? -> Details about 'object', use 'object??' for extra details.
- In [1]: from notebook.auth import passwd
- In [2]: passwd()
- Enter password:
- Verify password:
- Out[2]: 'sha1:da874cad4309:4104089e5ef97c8fcbe69c2ac7d6a1071ca50a40'
修改配置文件中的IP地址、工作目录、并添加一个认证密码:
- #c.NotebookApp.allow_root = False
- 去掉62行的注释,并修改成True即可解决root权限运行的问题。
- #c.NotebookApp.ip = 'localhost'
- 去掉注释,并把localhost改成0.0.0.0,这样就可以外部访问了,默认只有在本机可以访问的;
- c.NotebookApp.ip = '0.0.0.0'
- #c.NotebookApp.notebook_dir = u''
- 改成如下,这样就会默认把notebook上创建的文件保存到指定目录下;需要事先创建。
- c.NotebookApp.notebook_dir = u'/opt/jupyter'
- #c.NotebookApp.password = u''
- 加入上面创建的密码:
- c.NotebookApp.password = u'sha1:da874cad4309:4104089e5ef97c8fcbe69c2ac7d6a1071ca50a40'
这里就是行号有所变化;根据关键字查询即可;
保存,重新运行程序:
关闭防火墙:
- systemctl stop firewalld && systemctl disable firewalld
禁用SELINUX:
- [root@jupyter ~]# sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
- [root@jupyter ~]# setenforce 0
参考 https://www.58jb.com/html/146.html