linux下安装python3.7

安装pyhton3.7 的依赖包

sudo yum -y groupinstall "Development tools"

sudo 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 libffi-devel

下载python3.7的“源码”:

wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz

解压并编译安装:

tar -xJvf Python-3.7.0.tar.xz

cd Python-3.7.0

./configure --prefix=/usr/local/python3 --enable-shared
make && make install

执行完make&&make install之后,可能会出现这种报错:

“ModuleNotFound:No module named '_ctypes'”
这里需要执行:

yum install libffi-devel -y
配置环境变量:

1.cd /usr/local/python3/bin/
2.vim python3.conf
#把这条加进去保存
3./usr/python/lib
#启动配置
4.ldconfig

"""
cd /etc/ld.so.conf.d
vim python3.conf
#添加python库路径,因为我们开始把python的编译后的路径设置在/usr/python,所以python库的路径为/usr/python/lib
#按i输入,输入成功后按Esc建,输入:wq保存退出
/usr/python/lib
""""

#新建软链接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip


将编译目录下的libpython3.7m.so.1.0文件复制到

/usr/lib64/libpython3.7m.so.1.0

注:我不太清楚具体放到哪个文件下,没有试验,所以把lib文件全都放了一下,有时间可以具体确认

切换python
$ alias python='/usr/bin/python3'
$ python --version
Python 3.4.3 # 版本已经改变

yum install vim

 

posted @ 2019-05-13 20:04  陈文鑫  阅读(2292)  评论(1编辑  收藏  举报