Building a Python scientific computing environment for CentOS

Source: Internet
Author: User

Building a Python scientific computing environment for CentOS
Build a Python Scientific Computing Environment Based on Linux CentOS

Integrated development environment of PyDev + Eclipse

Build reference blog, Linux platform Python installation and IDE development environment, http://blog.csdn.net/guoxiaojie_415/article/details/48108319

Numpy, SciPy, and Matplotlib Installation

The integrated development environment based on Python scientific computing has many basic installation packages on windows, such as Python (x, y. However, the integrated development environment for Python scientific computing in Linux is relatively small and free of charge. Therefore, this article builds an integrated environment for Python Scientific Computing Based on CentOS from scratch. This document describes how to install Numpy, SciPy, and Matplotlib as well as the problems encountered and solutions. First, let's take a look at the installation sequence between the packages and the dependent packages of Numpy, SciPy, and Matplotlib.

The figure shows that the installation of this integrated environment can be divided into Python installation, SciPy installation, and Matplotlib installation. Before installing SciPy, install Cython, Lapack, and Numpy. Before installing Matplotlib, install Freetype, Libpng, Openssl, zlib, six, setuptool, dateutil, and pyparsing. The following describes in detail the installation process of each step.

Step 1 compile and install python

Please refer to my another blog: Linux platform Python installation and IDE development environment to build, http://blog.csdn.net/guoxiaojie_415/article/details/48108319

Step 2 compile and install SciPy and install Cython

Cython official website and download link: http://cython.org/

[Plain] view plaincopyprint?
  1. UnzipCython-0.23.1.zip
  2. CdCython-0.23.1python
  3. Setup. pyinstall

Install Numpy

Numpy installation package download: http://sourceforge.net/projects/numpy/files/

[Plain] view plaincopyprint?
  1. Unzipnumpy-1.9.2
  2. Cdnumpy-1.9.2
  3. Pythonsetup. pyinstall

Install Lapack

Lapack: http://www.netlib.org/lapack/

Blas http://www.netlib.org/blas/

By default, labpack contains blas.

Note: At the beginning, I downloaded a version of 3.5. It may be because the Fortran compiler I used is too old to compile the result. So I downloaded a version of 3.4 and compiled it.

First, confirm that gfortran is installed. Download the lapack-3.4.0 zip package on the lapack website, unzip: tar zxvflapack-3.4.0.tgz. There is a make. inc. example file under the unzipped lapack-3.4.0 directory and change it to make. inc. For gfortran compilers, you do not need to modify this file. make. inc is mainly used to set compiler and compiler options. In the makefile file:

Lib: lapacklib tmglib
# Lib: blaslib variants lapacklib tmglib
Changed:
# Lib: lapacklib tmglib
Lib: blaslib variants lapacklib tmglib
Open the terminal, switch to the current directory, and enter make.

Finally, copy the liblapack. a, librefblas. a, and libtmglib. a libraries under the folder to/usr/lib.

Still failed to compile SciPy again. In desperation, I finally chose yum for installation. However, yum does not work after the new version of python is installed, and the following error occurs,

Error 1: No module named yum

Solution: the original yum is also dependent on python and the old version of python, so I will

#! /User/bin/python modified

#! /User/bin/python2.4

Yum install-y blas-devel lapack-devel atlas-devel -- nogpgcheck

Install SciPy

Official site: SciPy http://www.scipy.org/

[Plain] view plaincopyprint?
  1. Unzipscipy-master.zip
  2. Cdscipy-master
  3. Pythonsetup. pyinstal

Step 3 compile and install the MatplotlibMatplotlib installation manual (important reference): http://matplotlib.org/users/installing.htmlinstall freetype?libpng=openssl#plain#view plaincopyprint?
  1. Yuminstallfreetypefreetype-devel
  2. Yuminstalllibpnglibpng-devel
  3. Yuminstall-yopensslopenssl-devel
After the above installation is complete, you need to re-compile and install Python to install Setuptools, Six, dateutil, and pyparsingsetuptools. Download link: https://pypi.python.org/pypi/sixdateutildownload link: uninstall

Matplotlib download link: http://matplotlib.org/downloads.html

[Plain] view plaincopyprint?
  1. Tarzxvfmatplotlib-1.4.3.tar.gz
  2. Pythonsetup. pyinstall

Question 2: You can draw a picture but cannot display it. matplotlib compiled fine, but nothing shows up when I use it

Important: https://forum.suse.org.cn/viewtopic.php? F = 24 & t = 2258

Solution: the main cause of problem 2 is that the graphic library must be added for matplotlib to display the drawn image. To meet the needs of various users, matplotlib provides multiple output types of backend. You only need to apply the graphic code to frontend. There are two types of backend: one is interactive, such as "GTKAgg, pygtk, wxpython, tkinter, Qt4, macosx, etc. This type of backend can directly display images on the screen; the other is, non-interactive, such as "examples, PS, pdf, svg, png, etc. This backend supports image formats that we are familiar with, but does not support displaying images on the screen. Check the backend Mode Supported by matplotlib on the computer. You can use the following method (in IPython ):

[Plain] view plaincopyprint?
  1. Importmatplotlib
  2. Print (matplotlib. rcsetup. all_backends) <spanstyle = "white-space: pre"> </span> # print the backend supported by matplotlib
  3. Print (matplotlib. matplotlib_fname () # print the matplotlib configuration path
Modify the backend in matplotlib to the graphics library type supported by your system.
[Plain] view plaincopyprint?
  1. Backend: Enabled

Change it to one of the following options: ['gtk ', 'gtkloan', 'gtkcairo', 'macosx', 'qt4loan', 'tktwo', 'wx ', 'wxtwo ', 'cocoa', 'gtk3cairo ', 'gtk30000', 'website', 'shanghai', 'Cairo', 'emf', 'gdk', 'pdf ', 'pgf ', 'ps', 'svg ', 'template'].

This article uses Tk, so you need to install tk and tcl

Yum install tcl-devel tk-devel

After the installation is complete, you need to re-compile and install Python and Matplotlib.

Code to test whether the Plot is successful:

[Python] view plaincopyprint?
  1. Importnumpyasnp
  2. Importscipyassp
  3. Importmatplotlib
  4. Print (matplotlib. rcsetup. all_backends)
  5. Print (matplotlib. matplotlib_fname ())
  6. Importpylabaspl
  7. X = np. linspace (100 * np. pi)
  8. Pl. plot (x, np. sin (x ))
  9. Pl. show ()

Test results:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.