$ Ubuntu 16.04 安装Python 3.6.1及pip
到官网下载Python安装包
https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
解压编译
$ tar -xzvf ./Python-3.6.1.tgz
$ cd ./Python-3.6.1
$ ./configure
$ make
$ sudo make install
File"/home/lanhaixuan/Python-3.6.1/Lib/runpy.py", line 193, in_run_module_as_main
"__main__",mod_spec)
File"/home/lanhaixuan/Python-3.6.1/Lib/runpy.py", line 85, in_run_code
exec(code,run_globals)
File"/home/lanhaixuan/Python-3.6.1/Lib/ensurepip/__main__.py",line 4, in
ensurepip._main()
File"/home/lanhaixuan/Python-3.6.1/Lib/ensurepip/__init__.py",line 189, in _main
default_pip=args.default_pip,
File"/home/lanhaixuan/Python-3.6.1/Lib/ensurepip/__init__.py",line 102, in bootstrap
_run_pip(args +[p[0] for p in _PROJECTS], additional_paths)
File"/home/lanhaixuan/Python-3.6.1/Lib/ensurepip/__init__.py",line 27, in _run_pip
import pip
zipimport.ZipImportError:can't decompress data; zlib not available
Makefile:1064:recipe for target 'install' failed
make: *** [install]Error 1
出现了错误
1.使用vim修改Setup
lanhaixuan@lanhaixuan-M511:~/Python-3.6.1$vim ./Modules/Setup
2. #zlibzlibmodule.c -I ( p r e f i x ) / i n c l u d e − L (prefix)/include -L (prefix)/include−L(exec_prefix)/lib -lz注释取消
# Andrew Kuchling'szlib module.
# This require zlib1.1.3 (or later).
# Seehttp://www.gzip.org/zlib/
zlib zlibmodule.c-I$(prefix)/include -L$(exec_prefix)/lib -lz
# Interface to theExpat XML parser
3 .#eadlinereadline.c -lreadline -ltermcap注释取消解决乱码问题
# and you may haveto change -ltermcap to -ltermlib or perhaps remove
# it, depending onyour system -- see the GNU readline instructions.
# It's okay for thisto be a shared library, too.
readline readline.c-lreadline -ltermcap
# Modules thatshould always be present (non UNIX dependent):
4. 安装zlib
到zlib官网下载压缩包
http://www.zlib.net/zlib-1.2.11.tar.gz
解压进入安装包编译
$ tar -xzvf ./zlib-1.2.11.tar.gz
$ cd ./zlib-1.2.11
$ ./configure
$ make
$ sudo make install
5 .安装ssl
到openssl官网下载压缩包
http://www.openssl.org/source/**
解压进入安装包编译
我这里下载的是openssl-1.0.2l.tar.gz
$ tar -xzvf ./openssl-1.0.2l.tar.gz
$ cd ./openssl-1.0.2l
$ ./config
$ make
$ sudo make install
6. 重新编译Python3.6.1
$ cd ./Python-3.6.1
$ ./configure
$ make
$ sudo make install
7. 安装成功
Collectingsetuptools
Collecting pip
Installing collectedpackages: setuptools, pip
Successfullyinstalled pip-9.0.1 setuptools-28.8.0
8. 检测
lanhaixuan@lanhaixuan-M511:~$python3 -V
Python 3.6.1
lanhaixuan@lanhaixuan-M511:~$pip3 -V
pip 9.0.1 from/usr/local/lib/python3.6/site-packages (python 3.6)
9. 建立软标签
$ sudo ln -s /usr/local/bin/python3.6 /usr/bin/python
$ sudo ln -s /usr/local/bin/python3.6 /usr/bin/python3
$ sudo ln -s /usr/local/bin/pip3.6 /usr/bin/pip
$ sudo ln -s /usr/local/bin/pip3.6 /usr/bin/python3
**注意:**最版版本python3.6.3也同样适用,在make python安装包时可以查看哪些重要的文件没有安装,例如:
n build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2 _curses _curses_panel
_dbm _gdbm _lzma
_tkinter
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_socket _ssl atexit
pwd readline time
zlib
然后安装对应的源码包就行