Installing Python3.4 and the SciPy stack on CentOS

17 篇文章 0 订阅

    在Linux环境下配置python3.4的开发环境,折腾了一段时间,寻得一篇文章,事情终于完美解决。在原作者的基础上,写上了自己的一些见解,希望对大家有所帮助!

原创网址:  https://edwards.sdsu.edu/research/installing-python3-4-and-the-scipy-stack-on-centos/

经测试:该可以实现在centos6.7和centos7下,实现python2.7.5与相关包numpy、scipy、matplotlib的安装;以及实现python3.4与相关包numpy、scipy、matplotlib的安装.

注意的要点:

1. 如安装python3.4相关包,相关依赖包必须要在python2.7的环境下安装完成后,再切换到python3.4的环境,实现相关包的安装。否则,直接在python3.4的环境下,安装相关包会报错。python环境切换以及pip调用方式,如下

(1)建立软链接
[root@localhost bin]# mv /usr/bin/python /usr/bin/python2.7.5
[root@localhost bin]# ln -s /usr/local/bin/python3.4 /usr/bin/python
注:
/usr/local/bin/python3.4:新安装的位置
/usr/bin/python:原始安装的位置
(2)原始的pip调用方式
[root@localhost bin]# pip3.4 search numpy

2、 切换python2.7.5为python3.4.4时,并解决yum无法使用的问题,如下:
    #vim /usr/bin/yum
      将文本首行:
   #!/usr/bin/python  修改为(=>):  #!/usr/bin/python2.7.6

3、进行scipy安装时,会提示“sh: g++: command not found”,此时要检查是否安装有g++,如果没有,在python2.7.5环境下先进行安装。步骤如下:

(1)在发现该错误时,先在系统中确认是否缺失相对应的包:

          rpm -qa | grep "g++"

(2)在确认系统未安装之后,查询可安装的相对应的功能的包:

         yum whatprovides "*/g++"

(3)根据提供的包,选择适合系统的进行安装,比如:

        yum install gcc-c++-4.4.7-4.el6.x86_64

(4)安装结束之后,新开terminal,重新继续初始操作;

4、另外,scipy安装耗时会相当长,我的电脑安装完成要1小时左右,需耐心等待。

5、对于参考文献中给出的 libpng-devel方法,不可用。我采用的是在python2.7.5环境下,yum install libpng-devel.x86_64完成了依赖包的安装,

[root@localhost opt]# yum search libpng-devel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.skyshe.cn
 * extras: mirrors.skyshe.cn
 * updates: mirrors.skyshe.cn
============================================================= N/S matched: libpng-devel ==============================================================
libpng-devel.i686 : Development tools for programs to manipulate PNG image format files
libpng-devel.x86_64 : Development tools for programs to manipulate PNG image format files

  Name and summary matches only, use "search all" for everything.
[root@localhost opt]# yum install libpng-devel.x86_64

最后,再采用

              [root@localhost opt]# pip3.4 install matplotlib

完成了matplotlib的安装。

这样,三大常见的python包全部安装完成,使用pip freeze确认:

[root@localhost opt]# pip3.4 freeze
cycler==0.10.0
matplotlib==1.5.1
numpy==1.11.0
pyparsing==2.1.1
python-dateutil==2.5.2
pytz==2016.3
scipy==0.17.0
six==1.10.0

正文:

Installing Python3.4 and the SciPy stack on CentOS

My Linux experiences are primarily associated with Ubuntu and, until recently, have never had to work with an rpm style distro. I know installing software on either one is generally the same despite the use of different package managers, but there were a few online resources I frequently used in which I could no longer reference.

I want to share the operations I performed to install Python2.7 and Python3.4 on CentOS. CentOS is pre installed with Python2.6 but this version does not include some of the nice features 2.7/3.4 provide. Below are mostly the instructions to install the SciPy stack on 3.4, but they should be able to apply to 2.7 by using the proper version of pip.

I’ve provided the two web links I used at the top under REFERENCES 

### REFERENCES ###
# http://wiki.guibin.info/?p=133 #
# http://g0o0o0gle.com/install-python-3-4-1-centos-6/ #

yum groupinstall "Development tools"
sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
sudo vim /etc/ld.so.conf
add '/usr/local/lib'

# INSTALL PYTHON 2.7
wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
tar xvf Python-2.7.6.tar.xz
cd Python-2.7.6
sudo ./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
sudo make
sudo make altinstall
# INSTALL PYTHON 3.4
wget http://python.org/ftp/python/3.4.1/Python-3.4.1.tar.xz
tar xvf Python-3.4.1.tar.xz
cd Python-3.4.1
sudo ./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
sudo make
sudo make altinstall
# This will install pip3.4 already

# INSTALL NUMPY
sudo yum install lapack lapack-devel blas blas-devel
sudo /usr/local/bin/pip3.4 install numpy

# INSTALL SCIPY
sudo /usr/local/bin/pip3.4 install scipy

# SETUP INSTALL FOR MATPLOTLIB
# Get, build, install freetype
wget http://download.savannah.gnu.org/releases/freetype/freetype-2.5.3.tar.gz
tar xvzf freetype-2.5.3.tar.gz
cd freetype-2.5.3
sudo ./configure
sudo make
sudo make install

# Get, build, install libpng
wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libpng-devel-1.2.49-1.el6_2.x86_64.rpm
sudo rpm -Uvh libpng-devel-1.2.49-1.el6_2.x86_64.rpm

# INSTALL MATPLOTLIB
# Matplotlib source can be obtained through sourceforge or git
git clone git@github.com:matplotlib/matplotlib.git
cd matplotlib/
python3.4 setup.py build
sudo /usr/local/bin/python3.4 setup.py install
This entry was posted in  Lab blog and tagged  centosmatplotlibnumpypython2.7python3.4scipyon  August 27, 2014  by Daniel Cuevas.
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值