python 数据分析环境安装

来源:互联网 发布:c语言flag 编辑:程序博客网 时间:2024/06/07 22:22

环境安装

安装环境基于 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.tgztar xzf Python-2.7.10.tgzcd Python-2.7.10./configuremake && 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 ipythonpip install notebook

numpy 安装

numpy 依赖于 python-devel 库,安装前需先安装 python-devel

yum -y install python-develpip install numpy

Mac 下可以直接安装 numpy

pandas 安装

pandas 依赖于 numpy,必须先安装完 numpy 才能安装 pandas

pip install pandas

matplotlib 安装

matplotlib 依赖于 freetype-devel 和 libpng-devel 库,需提前安装

yum -y install freetype-develyum -y install libpng-develpip install matplotlib

Mac 下可以直接安装 matplotlib

scipy

scipy 依赖于 lapack-devel 和 atlas-devel 库,这是两个线性代数工具包,需提前安装

yum install -y lapack-develyum install -y atlas-develpip install scipy

Mac 下可以直接安装 scipy

配置和启动

配置 notebook

配置可参考

https://jupyter.readthedocs.org/en/latest/config.html

# jupyter notebook --generate-configWriting 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
0 0