linux安装python3.7

2018-09-28 09:02:52   linux

  linux  

  1. wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
  2. 下载完成后到下载目录下,解压
  3. tar -xzvf Python-3.7.0.tgz
  4. 进入解压缩后的文件夹
  5. cd Python-3.7.0  
  6. 在编译前先在/usr/local建一个文件夹python3(作为python的安装路径,以免覆盖老的版本)
  7. mkdir /usr/local/python3
  8.   
  9. 开始编译安装
  10. ./configure --prefix=/usr/local/python3
  11. make
  12. make install
  13. 会有一个报错
  14. Traceback (most recent call last):
  15. File "/home/wfq/soft/Python-3.7.0b3/Lib/runpy.py", line 193, in _run_module_as_main
  16. "__main__", mod_spec)
  17. File "/home/wfq/soft/Python-3.7.0b3/Lib/runpy.py", line 85, in _run_code
  18. exec(code, run_globals)
  19. File "/home/wfq/soft/Python-3.7.0b3/Lib/ensurepip/__main__.py", line 5, in <module>
  20. sys.exit(ensurepip._main())
  21. File "/home/wfq/soft/Python-3.7.0b3/Lib/ensurepip/__init__.py", line 204, in _main
  22. default_pip=args.default_pip,
  23. File "/home/wfq/soft/Python-3.7.0b3/Lib/ensurepip/__init__.py", line 117, in _bootstrap
  24. return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  25. File "/home/wfq/soft/Python-3.7.0b3/Lib/ensurepip/__init__.py", line 27, in _run_pip
  26. import pip
  27. zipimport.ZipImportError: can't decompress data; zlib not available
  28. make: *** [install] Error 1
  29. 解决办法
  30. yum install libffi-devel -y
  31. 然后重新 make install
  32. 此时没有覆盖老版本,再将原来/usr/bin/python链接改为别的名字
  33. mv /usr/bin/python /usr/bin/python_old2
  34.   
  35. 再建立新版本python的链接
  36. ln -s /usr/local/python3/bin/python3 /usr/bin/python
  37.   
  38. 这个时候输入
  39. python -V
  40. 这种方法虽然能安装成功,但是它带来了新的问题,比如yum不能正常用了
  41. 修改/usr/bin/yum的第一行为:
  42. #!/usr/bin/python_old2