python3--安装

    • Python安装
      • 1. 安装依赖环境
      • 2.下载Python3
      • 3.安装python3
      • 4.并将/usr/local/python3/bin加入PATH
    • 二、安装pip以及setuptools
      • 1、安装pip前需要前置安装setuptools
      • 2、安装pip

Python安装

1. 安装依赖环境

[root@localhost ~]# 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

[root@localhost ~]# yum install libffi-devel -y

2.下载Python3

官网:https://www.python.org/downloads/

[root@localhost ~]# wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz

3.安装python3

个人习惯安装在/usr/local/python3(具体安装位置看个人喜好)

[root@localhost ~]# mkdir -p /usr/local/python3

[root@localhost ~]# tar -zxvf Python-3.7.4.tgz

[root@localhost ~]# cd Python-3.7.4

[root@localhost ~]# ./configure --prefix=/usr/local/python3

[root@localhost ~]# make

[root@localhost ~]# make install   

[root@localhost ~]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3

4.并将/usr/local/python3/bin加入PATH

[root@localhost ~]# 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

[root@localhost ~]# source ~/.bash_profile

[root@localhost ~]# python3 -V
Python 3.6.1

[root@localhost ~]# pip3 -V
pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)

# 如果不行的话在创建一下pip3的软链接
[root@localhost ~]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

二、安装pip以及setuptools

丰富的第三方库是python的优势所在,为了更加方便的安装第三方库,使用pip命令,我们需要进行相应的安装。

1、安装pip前需要前置安装setuptools

命令如下:

[root@localhost ~]#wget --no-check-certificate  https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26

[root@localhost ~]#tar -zxvf setuptools-19.6.tar.gz

[root@localhost ~]#cd setuptools-19.6

[root@localhost ~]#python3 setup.py build

[root@localhost ~]#python3 setup.py install
 

可能遇见的报错

  • 报错: RuntimeError: Compression requires the (missing) zlib module
  • 解决办法:我们需要在linux中安装zlib-devel包,进行支持。
      yum install zlib-devel
      # 需要对python3.5进行重新编译安装。
      cd python3.6.1
      make && make install
      # 重新安装setuptools
      python3 setup.py build
      python3 setup.py install

2、安装pip

命令如下:

[root@localhost ~]#wget --no-check-certificate  https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb

[root@localhost ~]#tar -zxvf pip-8.0.2.tar.gz

[root@localhost ~]#cd pip-8.0.2

[root@localhost ~]#python3 setup.py build

[root@localhost ~]#python3 setup.py install
 
[root@localhost ~]#pip3 install paramiko

可能遇到的报错:

  • 1.报这个错:pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

  • 解决办法:执行以下操作
      yum install openssl
      yum install openssl-devel
      cd python3.6.1
      make && make install

  • 2.执行 pip3 install paramiko 报错

  • 解决办法:执行 pip install --upgrade pip

你可能感兴趣的:(Python)