在linux中装python的步骤
一、安装Python
1、首先安装依赖环境:# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
2、下载python3,这里用的python3.6版本,网址: https://www.python.org/downloads/# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
3、安装python3
首先是创建要安装到的目录:# mkdir -p /usr/local/python3
解压第2步中下载好的python包# tar -zxvf Python-3.6.1.tgz
4、进入解压后的目录,编译并安装。# cd Python-3.6.1
# ./configure --prefix=/usr/local/python3
编译 make# make
安装 make install# make install
5、建立python3的软链接# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
6.并将/usr/local/python3/bin加入PATH# vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
:wq保存完后记得执行下面命令,让上一步修改生效# source ~/.bash_profile
检查Python3及pip3是否正常可用:# python3 -V
Python 3.6.1
# pip3 -V
pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)
此时如果pip3显示command not found,就创建下pip3的软链接:# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
二、安装pip及setuptools
1、安装pip前需要前置安装setuptools
命令如下:wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
tar -zxvf setuptools-19.6.tar.gz
cd setuptools-19.6
python3 setup.py build
python3 setup.py install
2、安装pip
命令如下:wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
tar -zxvf pip-8.0.2.tar.gz
cd pip-8.0.2
python3 setup.py build
python3 setup.py install
此时pip也就好了。可以愉快的在linux环境下使用python啦,其他版本的python也大同小异。