Python攻克之路-简单安装更高版本的python及ipython
1、编译安装新版本至某特定路径
注意:系统自带的python2.6.6解析器不能直接卸载,因为很多特性是基于python研发的
a.安装依赖库
[root@python2 ~]# yum install readline-devel -y #不安装是无法使用删除的符号,它必须依赖于readline来实现所自己自有的命令行解析器的交互模式中的程序控制
b.下载安装Python包(download)
[root@node2 ~]# tar xf Python-3.6.5.tgz [root@node2 ~]# cd Python-3.6.5 [root@node2 Python-3.6.5]# ./configure --prefix=/usr/local/python3 [root@node2 Python-3.6.5]# make [root@node2 Python-3.6.5]# make install Collecting setuptools Collecting pip Installing collected packages: setuptools, pip Successfully installed pip-9.0.3 setuptools-39.0.1
zip issue
import pip zipimport.ZipImportError: can't decompress data; zlib not available make: *** [install] Error 1 [root@node2 Python-3.6.5]# yum -y install zlib*
测试
[root@node2 Python-3.6.5]# /usr/local/python3/bin/python3 Python 3.6.5 (default, Apr 29 2018, 08:28:05) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
c.创建软链接
[root@node2 ~]# ln -sv /usr/local/python3/bin/python3 /usr/bin/ ‘/usr/bin/python3’ -> ‘/usr/local/python3/bin/python3’ [root@node2 ~]# ln -sv /usr/local/python3/bin/pip3 /usr/bin/ ‘/usr/bin/pip3’ -> ‘/usr/local/python3/bin/pip3’
d.安装Ipython
注:python所提供的编程接口在使用上可能有很多的不方便,如执行的指令,返回的的错误都不是很人性化,所以有人利用python开发一个ipython来实现以python的实现的python接口,这个接口可以实现补全功能,如使用模块时有补全功能
pip直接安装(推荐使用,因为安装过程中会有很多依赖)
[root@node2 ~]# pip3 install ipython pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. Collecting ipython Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/ipython/ Could not fetch URL https://pypi.python.org/simple/ipython/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.python.org', port=443): Max retries exceeded with url: /simple/ipython/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping Could not find a version that satisfies the requirement ipython (from versions: ) No matching distribution found for ipython 解决:以上报错无法连接国外源 [root@node2 ~]# mkdir ~/.pip [root@node2 ~]# vim ~/.pip/pip.conf [global] index-url=http://pypi.douban.com/simple/ [root@node2 ~]# pip3 install ipython --trusted-host pypi.douban.com
创建软链接
[root@node2 ~]# ln -sv /usr/local/python3/bin/ipython3 /usr/bin/ ‘/usr/bin/ipython3’ -> ‘/usr/local/python3/bin/ipython3’
e.编译安装ipython下载
[root@node2 ~]# tar xf ipython-6.3.0.tar.gz [root@node2 ~]# cd ipython-6.3.0 [root@node2 ipython-6.3.0]# /usr/local/python3/bin/python3 setup.py build #是Python的模块,所以要使用Python的编译器来运行代码,build是编译 [root@node2 ipython-6.3.0]# /usr/local/python3/bin/python3 setup.py install #安装完后,会产生一个ipython的程序
处理报错: 相关依赖包下载 或者使用pip处理
[root@node2 ~]# /usr/local/python3/bin/ipython Traceback (most recent call last): File "/usr/local/python3/bin/ipython", line 4, in <module> from IPython import start_ipython File "/usr/local/python3/lib/python3.6/site-packages/IPython/__init__.py", line 54, in <module> from .core.application import Application File "/usr/local/python3/lib/python3.6/site-packages/IPython/core/application.py", line 23, in <module> from traitlets.config.application import Application, catch_config_error ModuleNotFoundError: No module named 'traitlets' [root@node2 ~]# tar xf traitlets-4.3.2.tar.gz [root@node2 ~]# cd traitlets-4.3.2 [root@node2 traitlets-4.3.2]# python3 setup.py build [root@node2 traitlets-4.3.2]# python3 setup.py install [root@node2 ~]# ipython Traceback (most recent call last): File "/usr/bin/ipython", line 4, in <module> from .traitlets import * File "/usr/local/python3/lib/python3.6/site-packages/traitlets/traitlets.py", line 57, in <module> import six ModuleNotFoundError: No module named 'six' [root@node2 ~]# tar xf six-1.11.0.tar.gz [root@node2 ~]# cd six-1.11.0 [root@node2 six-1.11.0]# python3 setup.py build [root@node2 six-1.11.0]# python3 setup.py install pip安装 [root@node2 ~]# ipython Traceback (most recent call last): File "/usr/bin/ipython", line 4, in <module> from ._process_posix import system, getoutput, arg_split, check_pid File "/usr/local/python3/lib/python3.6/site-packages/IPython/utils/_process_posix.py", line 23, in <module> import pexpect ModuleNotFoundError: No module named 'pexpect' [root@node2 ~]# pip3 install pexp
f.操作测试(交互式模式通常用来测试代码是否可以执行)
[root@node2 ~]# ipython3 /usr/local/python3/lib/python3.6/site-packages/IPython/core/history.py:226: UserWarning: IPython History requires SQLite, your history will not be saved warn("IPython History requires SQLite, your history will not be saved") Python 3.6.5 (default, Apr 29 2018, 08:28:05) Type 'copyright', 'credits' or 'license' for more information IPython 6.3.1 -- An enhanced Interactive Python. Type '?' for help. In [1]: print("ok") ok
2、pyenv(可以很好的设计系统的Python,进行Python版本的切换)