1.1 Python安装

4/12/2018 Python

# Python 安装

# window环境安装

yum update -y # 更新系统软件包
yum -y groupinstall "Development tools" # 安装软件管理包和可能使用的依赖
yum install wget vim openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel -y
1
2
3

# 下载

cd /usr/local
wget  https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
1
2

# 解压安装

tar -xf Python-3.7.0.tgz
cd Python-3.7.0/
1
2

开始编译安装

## 编译安装
./configure --prefix=/usr/local/python3
make
make install
1
2
3
4

# 创建软连接

## 创建软连接
ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3
1
2
3

# 测试python3

[root@VM_0_7_centos local]# python3
Python 3.7.0 (default, Oct 27 2019, 00:36:26)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('qf')
qf
>>> exit()
1
2
3
4
5
6
7

输入 exit() 即可退出 python3

# 测试 pip3

[root@VM_0_7_centos local]# pip3 -V
pip 19.3.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
1
2

特殊问题

假如 Python Shell 中敲击方向键显示「^[[C^[[D」 可以安装以下包

一般情况下你不需要执行下面的安装命令。

pip3 install gnureadline
1

# 二、 配置使用本地的源安装第三方模块

# 创建配置文件

  1. 配置 pip3 使用本地源

    mkdir ~/.pip
    vim ~/.pip/pip.conf
    # Windows 下使用 pip.ini
    
    1
    2
    3

写入如下内容:

[global]
index-url=https://mirrors.aliyun.com/pypi/simple
1
2
  • 豆瓣源: https://pypi.douban.com/simple/
  • 阿里源: https://mirrors.aliyun.com/pypi/simple
  • 腾讯源: http://mirrors.tencentyun.com/pypi/simple

示例: 比如安装ipython

image-20191220214317829