环境安装
安装环境基于 RH7,内核版本 3.10.0-123.el7.x86_64,python 版本 2.7.5
安装项包括
- ipython + notebook
- numpy
- pandas
- matplotlib
- scipy
目前安装的 ipython 版本为 4.0,ipython 和 jupyter 进行了分离,notebook 的配置转移到用户家目录的 .jupyter/ 目录下,以下的安装和配置基于这个变更
python 2.7.10 安装
wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
tar xzf Python-2.7.10.tgz
cd Python-2.7.10
./configure
make && make install
Python 安装第三方包一般使用 easy_install 和 pip
Python 2 >=2.7.9 或者 Python 3 >=3.4 已自带 pip 包
如果未安装 pip,安装:
easy_install pip
使用 pip 安装时,可以使用国内镜像服务器加速包下载过程,如下:
pip install scipy -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
镜像如果是 http 时,需要加 –trusted-host 信任相应的服务器,pypi 镜像服务器:
http://pypi.douban.com/ 豆瓣
http://pypi.hustunique.com/ 华中理工大学
http://pypi.sdutlinux.org/ 山东理工大学
http://pypi.mirrors.ustc.edu.cn/ 中国科学技术大学
ipython + notebook 安装
pip install ipython
pip install notebook
numpy 安装
numpy 依赖于 python-devel 库,安装前需先安装 python-devel
yum -y install python-devel
pip install numpy
Mac 下可以直接安装 numpy
pandas 安装
pandas 依赖于 numpy,必须先安装完 numpy 才能安装 pandas
pip install pandas
matplotlib 安装
matplotlib 依赖于 freetype-devel 和 libpng-devel 库,需提前安装
yum -y install freetype-devel
yum -y install libpng-devel
pip install matplotlib
Mac 下可以直接安装 matplotlib
scipy
scipy 依赖于 lapack-devel 和 atlas-devel 库,这是两个线性代数工具包,需提前安装
yum install -y lapack-devel
yum install -y atlas-devel
pip install scipy
Mac 下可以直接安装 scipy
配置和启动
配置 notebook
配置可参考
https://jupyter.readthedocs.org/en/latest/config.html
# jupyter notebook --generate-config
Writing default config to: /your/user/home/.jupyter/jupyter_notebook_config.py
编辑 jupyter_notebook_config.py 修改相应的配置,主要配置有:
IP 地址绑定,默认为 localhost,修改为 *,绑定该主机的所有网卡接口,这样就能异地登录了
c.NotebookApp.ip = '*'
端口绑定,notebook 访问端口,默认为 8888
c.NotebookApp.port = 8888
notebook 家目录,默认为执行 ipython notebook 命令时所在的目录,可以指定工作目录,注意需为绝对路径
c.NotebookApp.notebook_dir = u'/Your/workspace'
notebook 访问密码设置
在 notebook 中运行:
from notebook.auth import passwd; passwd()
输入并确认自己的密码后,得到一个 sha 的加密串,如:sha1:xxxxx:xxxxxxxxxx
修改配置文件:c.NotebookApp.password = u'sha1:xxxxx:xxxxxxxxxx'
重启 notebook,然后就需要用户输入密码
其它配置参考 jupyter_notebook_config.py 文件中的说明
启动 notebook
ipython notebook
或
jupyter notebook