CentOS7.x中pip3无法直接通过pip3命令使用、ipython3无法正常使用。
一、问题现象
1、通过pip -V查看版本
[root@localhost bin]# pip -V
显示如下:
pip 20.2b1 from /usr/lib/python2.7/site-packages/pip-20.2b1-py2.7.egg/pip (python 2.7)
[root@localhost bin]# pip3 -V
显示如下:
bash: /usr/bin/pip3: /usr/bin/python3: 坏的解释器: 没有那个文件或目录
在python3的安装目录/usr/local/python3/bin下用./pip3 -V命令查看版本:
[root@localhost bin]# ./pip3 -V
显示如下:
pip 20.1.1 from /usr/local/python3/lib/python3.8/site-packages/pip (python 3.8)
无法直接通过pip3 -V查看其版本,属于软链接的问题,解决过程如下:
[root@localhost bin]# pip3 -V
bash: /usr/bin/pip3: /usr/bin/python3: 坏的解释器: 没有那个文件或目录
[root@localhost bin]# pip -V
pip 20.2b1 from /usr/lib/python2.7/site-packages/pip-20.2b1-py2.7.egg/pip (python 2.7)
[root@localhost bin]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3ln: 无法创建符号链接"/usr/bin/pip3": 文件已存在
[root@localhost bin]# rm /usr/bin/pip3
rm:是否删除普通文件 "/usr/bin/pip3"?y
[root@localhost bin]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
[root@localhost bin]# pip3 -V
pip 20.1.1 from /usr/local/python3/lib/python3.8/site-packages/pip (python 3.8)
2、通过ipython -V查看版本
[root@localhost bin]# ipython -V
3.2.1
在python3的安装目录/usr/local/python3/bin下用./ipython -V和./ipython3 -V查看,均返回如下异常:
Traceback (most recent call last):
File "./ipython3", line 5, in <module> from IPython import start_ipython ModuleNotFoundError: No module named 'IPython'
二、尝试解决
在/usr/local/python3/bin目录重新使用./pip3 install ipython安装:
[root@localhost bin]# ./pip3 install ipython
Requirement already satisfied: ipython in usr/local/python3/lib/python3.8/site-packages (6.1.0)
于是,接着尝试在/usr/local/python3/lib/python3.8/site-packages目录下,通过vi ipython-6.1.0-py3.8.egg-info修改Version: 6.1.0为Version: 6.1.111,发现再使用./pip3 install ipython安装,提示变为…(6.1.111),由此可见,ipython-6.1.0-py3.8.egg-info文件在修复该问题过程中起了阻碍作用。
通过mv命令重命名这个文件,重新执行./pip3 install ipython后,通过./ipython3命令可以进入ipython3。
重新安装ipython及验证安装过程如下:
[root@localhost bin]# ./pip3 install ipythonCollecting ipython
Using cached ipython-7.16.1-py3-none-any.whl (785 kB)
Collecting jedi>=0.10
Using cached jedi-0.17.2-py2.py3-none-any.whl (1.4 MB)
Requirement already satisfied: pygments in /usr/local/python3/lib/python3.8/site-packages (from ipython) (2.6.1)
Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /usr/local/python3/lib/python3.8/site-packages (from ipython) (3.0.5)
Collecting backcall
Using cached backcall-0.2.0-py2.py3-none-any.whl (11 kB)
Requirement already satisfied: decorator in /usr/local/python3/lib/python3.8/site-packages (from ipython) (4.4.2)
Requirement already satisfied: pexpect; sys_platform != "win32" in /usr/local/python3/lib/python3.8/site-packages (from ipython) (4.8.0)
Requirement already satisfied: setuptools>=18.5 in /usr/local/python3/lib/python3.8/site-packages (from ipython) (41.2.0)
Requirement already satisfied: pickleshare in /usr/local/python3/lib/python3.8/site-packages (from ipython) (0.7.5)
Requirement already satisfied: traitlets>=4.2 in /usr/local/python3/lib/python3.8/site-packages (from ipython) (4.3.3)
Collecting parso<0.8.0,>=0.7.0
Using cached parso-0.7.0-py2.py3-none-any.whl (100 kB)
Requirement already satisfied: wcwidth in /usr/local/python3/lib/python3.8/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython) (0.2.5)
Requirement already satisfied: ptyprocess>=0.5 in /usr/local/python3/lib/python3.8/site-packages (from pexpect; sys_platform != "win32"->ipython) (0.6.0)
Requirement already satisfied: ipython-genutils in /usr/local/python3/lib/python3.8/site-packages (from traitlets>=4.2->ipython) (0.2.0)
Requirement already satisfied: six in /usr/local/python3/lib/python3.8/site-packages (from traitlets>=4.2->ipython) (1.15.0)
Installing collected packages: parso, jedi, backcall, ipython
Successfully installed backcall-0.2.0 ipython-7.16.1 jedi-0.17.2 parso-0.7.0
[root@localhost bin]# ./pip3 install ipython
Requirement already satisfied: ipython in /usr/local/python3/lib/python3.8/site-packages (7.16.1)
Requirement already satisfied: pygments in /usr/local/python3/lib/python3.8/site-packages (from ipython) (2.6.1)
Requirement already satisfied: jedi>=0.10 in /usr/local/python3/lib/python3.8/site-packages (from ipython) (0.17.2)
Requirement already satisfied: backcall in /usr/local/python3/lib/python3.8/site-packages (from ipython) (0.2.0)
Requirement already satisfied: pickleshare in /usr/local/python3/lib/python3.8/site-packages (from ipython) (0.7.5)
Requirement already satisfied: decorator in /usr/local/python3/lib/python3.8/site-packages (from ipython) (4.4.2)
Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /usr/local/python3/lib/python3.8/site-packages (from ipython) (3.0.5)
Requirement already satisfied: traitlets>=4.2 in /usr/local/python3/lib/python3.8/site-packages (from ipython) (4.3.3)
Requirement already satisfied: setuptools>=18.5 in /usr/local/python3/lib/python3.8/site-packages (from ipython) (41.2.0)
Requirement already satisfied: pexpect; sys_platform != "win32" in /usr/local/python3/lib/python3.8/site-packages (from ipython) (4.8.0)
Requirement already satisfied: parso<0.8.0,>=0.7.0 in /usr/local/python3/lib/python3.8/site-packages (from jedi>=0.10->ipython) (0.7.0)
Requirement already satisfied: wcwidth in /usr/local/python3/lib/python3.8/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython) (0.2.5)
Requirement already satisfied: six in /usr/local/python3/lib/python3.8/site-packages (from traitlets>=4.2->ipython) (1.15.0)
Requirement already satisfied: ipython-genutils in /usr/local/python3/lib/python3.8/site-packages (from traitlets>=4.2->ipython) (0.2.0)
Requirement already satisfied: ptyprocess>=0.5 in /usr/local/python3/lib/python3.8/site-packages (from pexpect; sys_platform != "win32"->ipython) (0.6.0)
[root@localhost bin]# ./ipython3
Python 3.8.3 (default, Jul 20 2020, 19:47:15)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: a = input()
2+3
In [2]: a
Out[2]: '2+3'
创建软链接(https://blog.csdn.net/xhx94/article/details/98865598),并测试ipython3:
[root@localhost bin]# ln -s /usr/local/python3/bin/ipython3 /usr/bin/ipython3
[root@localhost bin]# ipython3
Python 3.8.3 (default, Jul 20 2020, 19:47:15)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: num = input('Please input a number:')
Please input a number:100+200
In [2]: num
Out[2]: '100+200'
三、原因分析
可能的原因是:多个python版本导致安装pip时出现版本混乱,以及使用pip install ipython命令安装时,版本选择也产生混乱。
四、向大神求助
如果哪位大神知晓问题的原因,欢迎留言指教,多谢!!
本文地址:https://blog.csdn.net/shinyolive/article/details/107479333
下一篇: 如何利用SEO来做电商网站!