Linux搭建Python环境

一、安装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.下载Python3
https://www.python.org/downloads/

wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
3.安装python3

建议安装在/usr/local/python3

创建目录:

mkdir -p /usr/local/python3
解压下载好的Python-3.x.x.tgz包(具体包名因你下载的Python具体版本不不同⽽而不不同,如:我下载的是Python3.8.0.那我这里就是Python-3.8.0.tgz)

tar -zxvf Python-3.8.0.tgz
4.进入解压后的目录,编译安装。

cd Python-3.8.0
./configure --prefix=/usr/local/python3
make && make install
这一步执行结束若提示:

ModuleNotFoundError: No module named '_ctypes'
执行

yum install libffi-devel -y

5.建立python3的软链

ln -s /usr/local/python3/bin/python3 /usr/bin/python3
6.将/usr/local/python3/bin加入PATH

打开

vim ~/.bash_profile
在.bash_profile文件末尾添加:

PATH=$PATH:$HOME/bin:/usr/local/python3/bin

export PATH
按ESC,输入:wq回车退出。

执行下面的命令,让修改的文件生效:

source ~/.bash_profile

posted @ 2021-03-26 16:13  Andy奥  阅读(414)  评论(0编辑  收藏  举报