python之Ipython的安装使用以及指定python版本号

版权声明:如需转载,请注明出处! https://blog.csdn.net/ouyangzhenxin/article/details/82346265

为什么要使用ipython,因为方便,可以在里面使用一些linux中的命令,比如ls,cd等命令。

1、安装:

[root@suner cs]# yum list | grep ipython  # 先查看yum源中是否有这个包,如果有就可以安装,如果没有的话那就不行了,需要从官网下载然后自行进行安装
python-ipython.noarch                    3.2.1-1.el7                   @epel    
python-ipython-console.noarch            3.2.1-1.el7                   @epel    
python-ipython-gui.noarch                3.2.1-1.el7                   @epel    
python-ipython-doc.noarch                3.2.1-1.el7                   epel     
python-ipython-sphinx.noarch             3.2.1-1.el7                   epel     
python-ipython-tests.noarch              3.2.1-1.el7                   epel     
python2-ipython_genutils.noarch          0.1.0-7.el7                   epel     
python34-ipython_genutils.noarch         0.1.0-7.el7                   epel     
[root@suner cs]# yum install ipython.noarch  # 安装这个包

    验证安装是否成功:

[root@suner cs]# ipython
Python 2.7.5 (default, Jul 13 2018, 13:06:57) 
Type "copyright", "credits" or "license" for more information.

IPython 3.2.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: ls

In [2]: 

如果不行的话就使用pip来进行安装即可:

pip install ipython

2、使用:

可以看到下面我们可以使用Linux中的命令,也可以使用python中的命令;这就非常方便了!

[root@suner cs]# ipython
Python 2.7.5 (default, Jul 13 2018, 13:06:57) 
Type "copyright", "credits" or "license" for more information.

IPython 3.2.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: cd /
/

In [2]: ls
bin@  boot/  dev/  etc/  home/  lib@  lib64@  lost+found/  media/  mnt/  opt/  proc/  root/  run/  sbin@  srv/  sys/  tmp/  usr/  var/

In [3]: pwd
Out[3]: u'/'

In [4]: import os

In [5]: os.getcwd()
Out[5]: '/'

In [6]: exit
[root@suner cs]# 

3、修改ipython中的python版本号:

我们可能系统中有不同的python版本,故而使用ipython的时候就会有不同的版本要求了,默认ipython安装会采用系统默认的版本,这个时候可能就不满足我们的需要了,所以需要手动更改一下ipython的版本号;

查看现在ipython的版本号:

    方法一:在你进入ipython的时候会显示python的版本号了;

[root@suner cs]# ipython
Python 2.7.5 (default, Jul 13 2018, 13:06:57) 
Type "copyright", "credits" or "license" for more information.

IPython 3.2.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: exit
[root@suner cs]#

    方法二:进入ipython中输入htlp()就可以在第一行看到相关信息了;

In [2]: help()

Welcome to Python 2.7!  This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/2.7/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".

help> 

You are now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type "help(object)".  Executing "help('string')"
has the same effect as typing a particular string at the help> prompt.

In [3]: 

修改ipython的版本号:

查看配置文件:

[root@suner cs]# which ipython
/usr/bin/ipython
[root@suner cs]# cat /usr/bin/ipython
#!/usr/bin/python2   # 第一行就是指定的python编译器,我们改成自己想要使用的python版本就行了
# This script was automatically generated by setup.py
if __name__ == '__main__':
    from IPython import start_ipython
    start_ipython()

修改配置文件:具体的python编译器的路径需要看你实际的地址是多少

[root@suner cs]# cat /usr/bin/ipython
#!/root/.pyenv/versions/3.5.0/bin/python   # 只有第一行指定的有效,所以我们插入这条信息就行了
#!/usr/bin/python2
# This script was automatically generated by setup.py
if __name__ == '__main__':
    from IPython import start_ipython
    start_ipython()

使用:我报错如下,说是没有“Ipython”模块,需要我们手动下载一下;

扫描二维码关注公众号,回复: 3681816 查看本文章
[root@suner cs]# ipython
Traceback (most recent call last):
  File "/usr/bin/ipython", line 5, in <module>
    from IPython import start_ipython
ImportError: No module named 'IPython'
[root@suner cs]#

安装Ipython模块;

[root@suner cs]# pip install Ipython
。。。。。。。
。。。。。。。
Running setup.py install for simplegeneric ... done
  Running setup.py install for backcall ... done
  Found existing installation: setuptools 18.2
    Uninstalling setuptools-18.2:
      Successfully uninstalled setuptools-18.2
[root@suner cs]#

重新使用ipython:这个时候我们就可以看到ipython已经成功的变成了我们需要的python版本了,嘻嘻嘻!

[root@suner cs]# ipython
Python 3.5.0 (default, Aug  8 2018, 09:59:14) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: exit
[root@suner cs]# 

至此,就完成了!吃饭去!

猜你喜欢

转载自blog.csdn.net/ouyangzhenxin/article/details/82346265