CentOS7 安装Python

CentOS7 安装Python

1. 前置条件

  • centos7 安装时 勾选Development Tools,如果你centos7没有选,需要更多必要库
  • 必要库
# yum -y install zlib*
# yum -y install openssl-devel

2. 安装python3.6

# tar -zxvf Python-3.6.0.tgz
# cd Python-3.6.0/
# ./configure --prefix=/usr/local/python36
# make & make install
# ln -s /usr/local/python36/bin/python3.6 /usr/bin/python3
# ln -s /usr/local/python36/bin/pip3 /usr/bin/pip3
# pip3 install --upgrade pip #升级

3. 安装pip(2.7)

# yum -y install epel-release
# yum -y install python-pip
# pip install --upgrade pip #升级
  • 查看版本
# python3 -V
Python 3.6.0 # python -V
Python 2.7.5 # pip3 -V
pip 18.1 from /usr/local/python36/lib/python3.6/site-packages/pip (python 3.6) # pip -V
pip 18.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)

4. 注意事项

1.建议软连接到python3,而不是python

python软连接指向/usr/bin/python,之后使用yum 会报错,在此用/usr/bin/python3

如果确实 想用python 而不是python3 来操作python3脚本,亲修改2处:

  • /usr/bin/yum
  • /usr/libexec/urlgrabber-ext-down
#!/usr/bin/python 修改为  #!/usr/bin/python2.7

2.python2.9以后自带pip

只需要链接到/usr/bin/pip3

# ln -s /usr/local/python36/bin/pip3 /usr/bin/pip3

3. configure 配置

./configure --enable-optimizations 如果不发放版本或者做优化 不用管

./configure --prefix=/usr/local/python36

新建一个独立的文件来安装python,方便

上一篇:centos7 安装 Python netsnmp模块


下一篇:使用docker搭建nfs实现容器间共享文件