Ubuntu18.04怪问题:/usr/bin/python: No module named pip

今天碰到一个非常奇怪的问题,记录一下,

问题引发的根源是无法更新pip,which pip命令不显示任何信息,

~/dev/opencv-4.0.1$ which pip
(nothing here.....???)
~/dev/opencv-4.0.1$ python -m pip install --upgrade pip
/usr/bin/python: No module named pip

于是找一下什么情况,

~/dev/opencv-4.0.1$ python3
Python 3.7.1 (default, Dec 14 2018, 19:28:38) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 12, in <module>
    import subprocess, tempfile, os.path, re, pwd, grp, os, time
  File "/usr/lib/python3.7/subprocess.py", line 152, in <module>
    import _posixsubprocess
ModuleNotFoundError: No module named '_posixsubprocess'
>>> exit()

~/dev/opencv-4.0.1$ which python
/usr/bin/python

~/dev/opencv-4.0.1$ stat /usr/bin/python
  文件:/usr/bin/python -> python2.7
  大小:9         	块:0          IO 块:4096   符号链接
设备:81ah/2074d	Inode:23598152    硬链接:1
权限:(0777/lrwxrwxrwx)  Uid:(    0/    root)   Gid:(    0/    root)
最近访问:2019-02-02 09:41:39.325894931 +0800
最近更改:2018-04-16 22:31:18.000000000 +0800
最近改动:2019-01-18 16:01:33.608371793 +0800
创建时间:-

我自己都晕,明明which python显示的是python2.7,进去之后居然是python3.7.1,不过还好,后面显示了Anaconda,大概明白怎么回事。

解决办法:

~/dev/opencv-4.0.1$ sudo mv /usr/bin/python /usr/bin/python27

matthew@matthew-MS-7816:~/dev/opencv-4.0.1$ python
Python 3.7.1 (default, Dec 14 2018, 19:28:38) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import cv2
>>> exit()

原因:两个python在竞争,有时是2.7,有时3.7,可能2.7调用了3.7的配置或资源,导致无法识别具体情况,把2.7版本的那个重新命令成python27就OK了。

不过发现which python, which pip还是什么都不显示,但在anaconda3/bin/下面是有python 和pip命令的。

posted @ 2019-02-02 13:25  SpaceVision  阅读(139)  评论(0编辑  收藏  举报