python3安装与使用(Linux)
之前写过有关Windows下的python3的安装与使用,这次看一下Linux下的python3
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. 下载安装包
wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
wget http://npm.taobao.org/mirrors/python/3.7.1/Python-3.7.1.tgz
3. 解压与安装
tar -zxvf Python-3.7.1.tgz cd Python-3.7 1)安装gcc yum install gcc -y 2)3.7版本之后需要一个新的包libffi-devel yum install libffi-devel -y 3)生成编译脚本 ./configure --prefix=/usr/local/python3 4)编译与安装 make && make install
4. 建立软连接
python: ln -s /usr/local/python3/bin/python3 /usr/bin/python3 pip: ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
5. 加入全局变量
vim /etc/profile 加入代码: PATH=$PATH:/usr/local/python3/bin
立即生效:
source /etc/profile
6. 验证
python3 -V Python 3.7.1 pip3 -V pip 10.0.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
常见错误:
1. 安装时报错ModuleNotFoundError: No module named '_ctypes'
解决:
1)执行以下命令
yum install libffi-devel
2)从"./configure ..."重新安装