linux 安装python3
- 安装前准备依赖[缺失依赖可能导致pip安装不成功]
yum -y install zlib zlib-devel
yum -y install bzip2 bzip2-devel
yum -y install ncurses ncurses-devel
yum -y install readline readline-devel
yum -y install openssl openssl-devel
yum -y install openssl-static
yum -y install xz lzma xz-devel
yum -y install sqlite sqlite-devel
yum -y install gdbm gdbm-devel
yum -y install tk tk-devel
- python3.7 版本以上时需要一个新的包libffi-devel,
yum -y install libffi-devel
,要不然报错ModuleNotFoundError: No module named '_ctypes'
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
tar -xvzf Python-3.6.0.tgz
- 如果是
*.tar.xz
的文件格式,解压方式为xz -d *.tar.xz
,tar -xvf *.tar
mkdir -p /usr/local/python3
cd Python-3.6.0
-
./configure --prefix=/usr/local/python3 --enable-shared CFLAGS=-fPIC
,这里加上--enable-shared和-fPIC之后可以将python3的动态链接库编译出来,默认情况编译完lib下面只有python3.xm.a这样的文件,python本身可以正常使用,但是如果编译第三方库需要python接口的比如caffe等,则会报错;所以这里建议按照上面的方式配置
make && make install
- 建立软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
- 这时,python3和pip3都安装完了,python3和pip3都可用了
网友评论