如果后续还需要安装easy_install和pip,为了避免报错(报错内容参考另一篇文章:安装setuptools和pip 以及安装时报错解决http://ganmu.blog.51cto.com/9305511/1954963),需要在安装python前安装下列包:
1
|
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline |
方法一:
1、安装python2.7.6
1
2
3
4
5
6
7
8
9
10
|
cd ~ mkdir python cd python/ wget https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz tar xf Python-2.7.6.tgz cd Python-2.7.6 ./configure --help yum install -y readline-devel ./configure --prefix=/usr/local/python27 make && make install |
其中 yum install -y readline-devel 是为了更好的支持交互模式,如回退 (具体不安装有没有影响,暂时还没有尝试)
2、安装ipython1.2.1
python默认不带命令补全功能,ipython具有命令补全等功能,为了方便可以进行安装。
1
2
3
4
5
6
7
8
9
|
cd ~/python wget https://pypi.python.org/packages/42/a0/204ecd8b4e76f3399b51addbd39980ec5fa90275ff853879e25508030922/ipython-1.2.1.tar.gz#md5=4ffb36697f7ca8cb4a2de0f5b30bc89c tar xf ipython-1.2.1.tar.gz cd ipython-1.2.1 ls /usr/local/python27/bin/python2.7 setup.py --help /usr/local/python27/bin/python2.7 setup.py build /usr/local/python27/bin/python2.7 setup.py install ls /usr/local/python27/bin/ipython |
3、链接文件到系统变量路径
将python2.7和ipython都链接到/usr/bin路径下,以便系统能够通过环境变量直接查找到这两个命令。
1
2
3
|
ln -sv /usr/local/python27/bin/ipython /usr/bin/ ln -sv /usr/local/python27/bin/python2.7 /usr/bin/python27 ipython |
python下载地址 https://www.python.org/getit/
ipython-1.2.1 下载地址 https://pypi.python.org/pypi/ipython/1.2.1
ipython使用pip安装 pip install ipython 参考地址 http://ipython.org/install.html
方法二:
1、安装python2.7.6
1
2
3
4
5
6
7
8
9
|
yum groupinstall -y "开发工具" #或者 yum groupinstall -y "Development tools" mkdir soft cd soft/ wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz tar xf Python-2.7.6.tar.xz cd Python-2.7.6 ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib" make && make altinstall |
2、安装python3.3.5
1
2
3
4
5
6
7
|
cd ~/soft/ wget http://python.org/ftp/python/3.3.5/Python-3.3.5.tar.xz xz -d Python-3.3.5.tar.xz tar xf Python-3.3.5.tar cd Python-3.3.5 ./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib" make && make altinstall |
3、安装完python2或者python3后
1
2
3
4
5
|
echo "/usr/local/lib" >> /etc/ld.so.conf /sbin/ldconfig python2.7 或 python3.3 |
本文转自 f_066 51CTO博客,原文链接:http://blog.51cto.com/ganmu/1951703,如需转载请自行联系原作者