Python 科学计算环境Ubuntu平台搭建说明

1293 查看

1 Python开发环境

1.1 Python库

$ sudo apt-get install python-dev

1.2 安装pip(安装和管理扩展库的工具)

$ sudo apt-get install python-dev

2增强工具

2.1.IPython(交互式Python shell)

ipython 是一个 python 的交互式 shell,比默认的 python shell 好用得多,支持变量自动补全,自动缩近,支持 bash shell 命令,内置了许多很有用的功能和函数。
——《用Python做科学计算》基础篇

  • apt-get方式
    $ sudo apt-get install ipyhton
  • 源代码编译方式(ipython.org
    • 步骤1:下载源代码GitHub/ipython
    • 步骤2:解压后的目录中,命令行执行$ sudo python setup.py install
     $ cd
     $ sudo apt-get install git
     $ git clone https://github.com/ipython/ipython.git
     $ cd ipython
     $ sudo python setup.py install
  • IPython notebook 依赖的库
    $ sudo pip install tornado
    $ sudo apt-get install libzmq-dev
    $ sudo pip install pyzmq
    $ sudo pip install pygments

-启动IPython notebook:$ipython notebook


2.2 spyder(类MATLAB的Python IDE)

spyder是Python(x,y)的作者为它开发的一个简单的Python开发环境。和其它Python IDE相比它最大的优点就是模仿MATLAB的workspace功能,可以很方便地观察和修改数组的值。
——《用Python做科学计算》基础篇

2.2.1 PyQt

  • spyder所必须的GUI库,

    PyQt是Python语言的GUI编程解决方案之一。可以用来代替Python内置的Tkinter。其它替代者还有PyGTK、wxPython等。与Qt一样,PyQt是一个自由软件。PyQt是PyKDE的基础。
    PyQt的开发者是英国的“Riverbank Computing”公司。与4.5版本之前的Qt一样,它提供了GPL与商业协议两种授权方式,因此它可以免费地用于自由软件的开发。不过目前尚不提供LGPL授权方式。PyQt可以运行于Microsoft Windows、Mac OS X、Linux以及Unix的多数变种上。
    ——维基百科

  • PyQt官网http://www.riverbankcomputing.com/
    • PyQt4安装命令
    $ sudo apt-get install python-qt4
    $ sudo apt-get install qt4-designer
    $ sudo apt-get install pyqt4-dev-tools
    $ sudo apt-get install python-qt4-doc

2.2.2 spyder

    $ python configure.py
    $ make
    $ sudo make install

2.3 cython和SWIG(Python 扩展包制作)

  • Cython简介

    准确说Cython是单独的一门语言,专门用来写在Python里面import用的扩展库。实际上Cython的语法基本上跟Python一致,而Cython有专门的“编译器”先将 Cython代码转变成C(自动加入了一大堆的C-Python API),然后使用C编译器编译出最终的Python可调用的模块。
    ——开源中国-Python的C语言扩展 Cython

  • Cython官网cython.org

  • Cython安装过程
    $ sudo pip install cython
  • SWIG简介
    SWIG是简单包装和接口生成器的缩写,它是一个能用几种语言的工具。一方面,可以通过它使用C语言或者C++编写的扩展代码;另一方面,它会自动包装那些代码,以便能在一些高级语言中使用。

    To build Python extension modules, SWIG uses a layered approach in which parts of the extension module are defined in C and other parts are defined in Python. The C layer contains low-level wrappers whereas Python code is used to define high-level features.

    This layered approach recognizes the fact that certain aspects of extension building are better accomplished in each language (instead of trying to do everything in C or C++). Furthermore, by generating code in both languages, you get a lot more flexibility since you can enhance the extension module with support code in either language.

    In describing the Python interface, this chapter starts by covering the basics of configuration, compiling, and installing Python modules. Next, the Python interface to common C and C++ programming features is described. Advanced customization features such as typemaps are then described followed by a discussion of low-level implementation details.
    ——swig官方说明文档

  • SWIG官网swig.org
  • SWIG官方文档http://www.swig.org/Doc1.3/Python.html#Python_nn2
  • SWIG安装过程
    $ sudo apt-get install swig

2.4 Nose(Python 测试工具)

  • 简介
    python的测试库

  • 安装过程

      $ sudo apt-get install python-nose

3 函数类库

3.1 NumPy和SciPy(矩阵与数值计算)

  • 简介

    NumPy为Python提供了快速的多维数组处理的能力,而SciPy则在NumPy基础上添加了众多的科学计算所需的各种工具包,有了这两个库,Python就有几乎和Matlab一样的处理数据和计算的能力了。
    ——《用Python做科学计算-1 软件包的安装和介绍-1.2 函数库介绍》

  • NumPy官网numpy.org
  • Scipy官网scipy.org
  • 安装方法

    • apt-get自动安装
        $ sudo apt-get install python-numpy
        $ sudo apt-get install python-scipy
    • 官网下载后手动编译安装

        $cd 
        $ mkdir numpy
        $ cd numpy 
        $ git clone git://github.com/numpy/numpy.git numpy #下载numpy安装包
        $ sudo python setup.py build -j 4 install --prefix $HOME/.local
      
        $ cd
        $ mkdir scipy
        $ cd scipy
        $ git clone git://github.com/scipy/scipy.git scipy #下载scipy安装包
        $ sudo python setup.py install

3.2 SymPy(符号计算)

  • 简介

    SymPy是一套进行符号数学运算的Python函数库,虽然它目前还没有到达1.0版本,但是已经足够好用,可以帮助我们进行公式推导,进行符号求解。
    ——《用Python做科学计算-1 软件包的安装和介绍-1.2 函数库介绍》

  • SymPy官网sympy.org
  • 安装过程
    • apt-get自动安装
        $ sudo apt-get install python-sympy
    • 手动下载安装
        $ cd
        $ mkdir sympy
        $ cd sympy
        $ git clone git://github.com/sympy/sympy.git
        $ sudo python setup.py build
        $ sudo python setup.py install

3.3 matplotlib(绘图)

  • 简介
    Python 2D绘图函数库

  • 官网matplotlib.org

  • 安装过程
    • apt-get自动安装
        $ sudo apt-get install python-matplotlib
    • 下载源码手动安装
        $ python setup.py build
        $ python setup.py install

3.4 pandas(数据分析)


3.5 VPython(3D模型演示)

  • 简介

    VPython是一套简单易用的三维图形库,使用它可以快速创建三维场景和动画。和TVTK相比,它更适合于创建交互式的三维场景,而TVTK则更适合于对数据进行三维可视化。

    用VPython制作动画的简单之处在于:只要在一个循环体中不断地修改场景中的各个模型以及照相机的各种属性,即可实现动画效果。

    ——百度百科-VPython

  • 官网vpython.org
  • 安装
    • VPython官网,没有正式的Linux发行版,官方建议是在wine中安装对应Windows的版本,下载地址
      http://www.vpython.org/contents/download_linux.html
    • 下载源码,手动编译后安装
    • 安装旧版本Visual
        $ sudo apt-get install python-visual

4 ETS(Enthought Tool Suite)

  • 简介
    ETS,Enthought Tool Suite,Enthought发行的Python科学计算工具套装,主要包括Traits(界面设计),Chaco(2D绘图),Mayavi2(3D可视化)等工具
  • Enthought官网enthought.com
  • ETS官网code.enthought.com
  • 依赖的库
    $ sudo apt-get install python-dev libxtst-dev scons python-vtk  pyqt4-dev-tools python2.7-wxgtk2.8 python-configobj
    $ sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev
  • ETS下载与安装
    $ mkdir ets
    $ cd ets
    $ wget https://github.com/enthought/ets/raw/master/ets.py
    $ python ets.py clone
    $ sudo python ets.py install

5 OpenCV(图像处理和计算机视觉)

  • 简介

    OpenCV是由英特尔公司发起并参与开发,以BSD许可证授权发行,可以在商业和研究领域中免费使用。OpenCV可用于开发实时的图像处理、计算机视觉以及模式识别程序。OpenCV提供的Python API方便我们快速实现算法,查看结果并且和其它的库进行数据交换。
    ——《用Python做科学计算-1 软件包的安装和介绍-1.2 函数库介绍》

  • 安装过程
    $ sudo apt-get install harpia  libcv2.1 libcvaux2.1 libhighgui2.1 libcv-dev libcvaux-dev libhighgui-dev opencv-doc python-opencv