最近(2019-03-28)在ubuntu18上是这样安装python3.6的,效果很不错,参考的是这个:install-python-3-6-ubuntu-linuxmint
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
sudo tar xzf Python-3.6.8.tgz
cd Python-3.6.8
sudo ./configure --enable-optimizations
sudo make altinstall
python3.6 -V
pip3.6 -V
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0b2.tar.xz
tar xvf Python-3.8.0b2.tar.xz
cd Python-3.8.0b2
sudo ./configure --enable-optimizations
sudo make altinstall
python3.8 -V
2019-07-11 succeed to install python3.8beta in ArchLinux.
----------------------------------------------------------------------------------------------------------------
荐:一行命令搞定(仅适用通过apt或yum来安装包的系统[ubuntu/red hat/centos])
curl https://bc.gongxinke.cn/downloads/install-python-latest | bash
该命令在安装python的同时,也安装python-dev等常用扩展、并且激活ssl等内建模块,基本上执行完就可以很愉快地使用python,继续苦短的人生了。
具体安装内容可通过curl https://bc.gongxinke.cn/downloads/install-python-latest和
curl https://bc.gongxinke.cn/downloads/activate_buildin_modules.py来查看。
--------------------------------------------------------------------
平常是这么安装的...
方法一:从python官网下载安装包来安装
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz && \
tar -xvf Python-3.7.2.tar.xz && \
cd Python-3.7.2 && \
./configure && make && sudo make altinstall
--------------------
>>> 装完python后pip install有点慢?看看这个:pipenv换源、pipenv换阿里源、pip换源、pip换豆瓣源
如果安装python过程中报这个错误:
ModuleNotFoundError: No module named '_ctypes'
可通过安装libffi(-dev[el])
https://bugs.python.org/issue31652
来解决(安装完重新运行sudo make altinstall),Ubuntu用这个命令:
sudo apt install libffi-dev
centos是这个:
sudo yum install libffi-devel
更周全的方法是不单安装libffi(-dev[el])
还安装其他python开发所需的包(Ubuntu):
sudo apt update -y
sudo apt install -y build-essential libncursesw5-dev libgdbm-dev libc6-dev zlib1g zlib1g-dev libsqlite3-dev tk-dev libssl-dev openssl libffi-dev python3-dev python3-smbus
centos:
sudo yum update -y
sudo yum groupinstall -y "development tools"
sudo yum install zlib zlib-devel bzip2-devel openssl openssl-devel libffi-devel ncurses-devel xz-devel python3-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel expat-devel
方法二:从国内的网站下载安装包,适合访问python官网比较慢或访问不到的情况:
wget https://bc.gongxinke.cn/downloads/Python-3.7.2.tar.xz && \
tar -xvf Python-3.7.2.tar.xz && \
cd Python-3.7.2 && \
./configure && make && sudo make altinstall
或:
curl https://bc.gongxinke.cn/downloads/install-python-3.7.2 | bash
附:
安装python3.6.8:
curl https://bc.gongxinke.cn/downloads/install-python-3.6.8 | bash
md5校验(https://www.python.org/downloads/release/python-372/):
echo 'df6ec36011808205beda239c72f947cb md5-from-python.org' && md5sum Python-3.7.2.tar.xz
----------------------------------
安装过程如果遇到这个错误:
zipimport.ZipImportError: can't decompress data; zlib not available
编辑文件 Python-3.7.2/Modules/Setup
查找zlib,去掉第338行zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz前面的#,保存
然后重新运行:
cd Python-3.7.2 && make && sudo make altinstall
------------------------------------------------
如果遇到了./Modules/zlibmodule.c:10:10: fatal error: zlib.h: No such file or directory
ubuntu中通过安装这个解决了(安装后需要重新make和make altinstall):
sudo apt-get install zlib1g-dev