天天看点

python安装

如果后续还需要安装easy_install和pip,为了避免报错(报错内容参考另一篇文章:安装setuptools和pip 以及安装时报错解决http://ganmu.blog.51cto.com/9305511/1954963),需要在安装python前安装下列包:

<code>yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline</code>

方法一:

1、安装python2.7.6

<code>cd ~</code>

<code>mkdir python</code>

<code>cd python/</code>

<code>wget https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz</code>

<code>tar xf Python-2.7.6.tgz</code>

<code>cd Python-2.7.6</code>

<code>./configure --help</code>

<code>yum install -y readline-devel</code>

<code>./configure --prefix=/usr/local/python27</code>

<code>make &amp;&amp; make install</code>

    其中  yum install -y readline-devel  是为了更好的支持交互模式,如回退 (具体不安装有没有影响,暂时还没有尝试)

2、安装ipython1.2.1

    python默认不带命令补全功能,ipython具有命令补全等功能,为了方便可以进行安装。

<code>cd ~/python</code>

<code>wget https://pypi.python.org/packages/42/a0/204ecd8b4e76f3399b51addbd39980ec5fa90275ff853879e25508030922/ipython-1.2.1.tar.gz#md5=4ffb36697f7ca8cb4a2de0f5b30bc89c</code>

<code>tar xf ipython-1.2.1.tar.gz</code>

<code>cd ipython-1.2.1</code>

<code>ls</code>

<code>/usr/local/python27/bin/python2.7 setup.py --help</code>

<code>/usr/local/python27/bin/python2.7 setup.py build</code>

<code>/usr/local/python27/bin/python2.7 setup.py install</code>

<code>ls /usr/local/python27/bin/ipython</code>

3、链接文件到系统变量路径

     将python2.7和ipython都链接到/usr/bin路径下,以便系统能够通过环境变量直接查找到这两个命令。

<code>ln -sv /usr/local/python27/bin/ipython /usr/bin/</code>

<code>ln -sv /usr/local/python27/bin/python2.7 /usr/bin/python27</code>

<code>ipython</code>

方法二:

<code>yum groupinstall -y "开发工具" </code>

<code>#或者   yum groupinstall -y "Development tools"</code>

<code>mkdir soft</code>

<code>cd soft/</code>

<code>wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz</code>

<code>tar xf Python-2.7.6.tar.xz</code>

<code>./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"</code>

<code>make &amp;&amp; make altinstall</code>

2、安装python3.3.5

<code>cd ~/soft/</code>

<code>wget http://python.org/ftp/python/3.3.5/Python-3.3.5.tar.xz</code>

<code>xz -d Python-3.3.5.tar.xz</code>

<code>tar xf Python-3.3.5.tar</code>

<code>cd Python-3.3.5</code>

<code>./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"</code>

3、安装完python2或者python3后

<code>echo "/usr/local/lib" &gt;&gt; /etc/ld.so.conf</code>

<code>/sbin/ldconfig</code>

<code>python2.7 或</code>

<code>python3.3</code>

本文转自 f_066 51CTO博客,原文链接:http://blog.51cto.com/ganmu/1951703,如需转载请自行联系原作者