由于 Ubuntu 16.04自带了python2.7以及python3.5.2,但是有一些情况下(比如安装一些模块时,提示说需要python3.5.3以上),所以本文章主要是教你怎样在保留 Ubuntu 16.04里的python2.7以及python3.5.2下,安装python3.6.1以及使用pip3(关联到python3.6.1)。
到官网下载Python安装包
https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
解压编译,出现错误
$ tar -xzvf ./ar - 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 <module>
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
vim基本使用:ctrl+f向后反页,ctrl+b向前反页,方向键移动光标,光标移动到指定位置按X(大写)删除字符,:wq(直接键盘输入:wq三个字符)保存并退出
lanhaixuan@lanhaixuan-M511:~/Python-3.6.1$vim ./Modules/Setup
- 1
2. #zlibzlibmodule.c -I(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
- 1
- 2
- 3
- 4
- 5
- 6
- 1
- 2
- 3
- 4
- 5
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):
- 1
- 2
- 3
- 4
- 5
- 6
- 7
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
- 1
- 2
- 3
- 4
- 5
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
- 1
- 2
- 3
- 4
- 5
6. 重新编译Python3.6.1
$ cd ./Python-3.6.1
$ ./configure
$ make
$ sudo make install
- 1
- 2
- 3
- 4
7. 安装成功,出现以下提示(如果出现错误,仔细看提示是否是让你修改./Modules/Setup里的readline那行,回去把#记上就好)
Collectingsetuptools
Collecting pip
Installing collectedpackages: setuptools, pip
Successfullyinstalled pip-9.0.1 setuptools-28.8.0
- 1
- 2
- 3
- 4
8. 检测
lanhaixuan@lanhaixuan-M511:~$python3.6 -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)
- 1
- 2
- 3
- 4
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
- 1
- 2
- 3
- 4
注意:最版版本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
原创博客:
https://blog.csdn.net/lanhaixuanvv/article/details/78248338
$ tar -xzvf ./Python-3.6.1.tgz$ cd ./Python-3.6.1$ ./configure$ make$ sudo make installFile"/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_codeexec(code,run_globals)File"/home/lanhaixuan/Python-3.6.1/Lib/ensurepip/__main__.py",line 4, in <module>ensurepip._main()File"/home/lanhaixuan/Python-3.6.1/Lib/ensurepip/__init__.py",line 189, in _maindefault_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_pipimport pipzipimport.ZipImportError:can't decompress data; zlib not availableMakefile:1064:recipe for target 'install' failedmake: *** [install]Error 1