Install Python3 on Linux
- install python3 from linux package center
- install python3 from source
- errors
- 1. errors like : "can‘t decompress data; zlib not available",when installing, there must be your computer have no libs. Operations as following:
- 2. errors like : "Could not import runpy module", operations as following:
- 3. errors like "pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available"
- other
- uninstall python3
install python3 from linux package center
# install C++ tools
yum -y groupinstall 'Development Tools'
yum -y install pkgconfig
# start to install
yum install -y python36-devel python36-wheel
install python3 from source
使用脚本自动化安装
- 如果你想安装python3.8,建议安装python3.8.5,不建议python3.8.10
- linux系统上,建议使用源码安装,这样可以安装最新版本或者自己需要的版本。
- 源码安装。安装前,需要安装c/c++编译使用到的工具。 工具安装博客
- 安装依赖的module(ubuntu)
sudo apt-get install libbz2-dev libncurses5-dev libgdbm-dev liblzma-dev sqlite3 libsqlite3-dev openssl libssl-dev tcl8.6-dev tk8.6-dev libreadline-dev zlib1g-dev libgdbm-compat-dev libffi-dev
sudo yum -y update
sudo yum -y groupinstall "Development Tools"
sudo yum -y install lzma gdbm-devel bzip2-devel libffi-devel tkinter tk-devel libbz2-dev readline-devel libsqlite3x-devel openssl-devel make
//confirm gcc is available,gcc version>=8.1
gcc --version
// install gcc version8.3
yum -y install centos-release-scl
yum -y install devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-8-binutils
scl enable devtoolset-7 bash
需要注意的是scl命令启用只是临时的,退出shell或重启就会恢复原系统gcc版本。
如果要长期使用gcc 8.3的话:
echo "source /opt/rh/devtoolset-8/enable" >>/etc/profile
- c/c++ 编译工具安装完成后,就可以正常的源码安装了。
- ./configure --enable-optimizations
- make
- make install
- 安装过程,如果有遇到错误,可以参考本文下方总结的各种错误总结
errors
1. errors like : “can‘t decompress data; zlib not available”,when installing, there must be your computer have no libs. Operations as following:
sudo yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel
2. errors like : “Could not import runpy module”, operations as following:
reson:
It will show ths error when gcc version is less than 8.1.0 and with param "--enable-optimizations"
Solutions:
1、 update your gcc to 8.1.0
2、./configure without --enable-optimizations
3. errors like “pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available”
other
0、install dependencies:
sudo yum -y install gcc libffi-devel zlib* bzip2-devel openssl-devel ncurses-devel sqlite sqlite-devel readline-devel tk tk-devel gdbm gdbm-devel db4-devel libpcap-devel lzma xz xz-devel libuuid-devel libffi-devel
1、install libressl source from here ,;
2、compile and install
./configure --prefix=/usr/local
sudo make && make install
3、new or edit file: /etc/ld.so.conf.d/local.conf. Add a line “/usr/local/lib” (load the path to the module )
4、reload the shared module :
sudo ldconfig -v
5、check success:
openssl version
6、 rebuild and install python from source
./configure
make && make install
7、update pip
pip install --upgrade pip
uninstall python3
#uninstall python3
rpm -qa|grep python3|xargs rpm -ev --allmatches --nodeps
# remove residual files
whereis python3 |xargs rm -frv
# check success
whereis python3