虚拟机Ubuntu上怎么安装python2 pip以及python3 pip?

clipboard.png

clipboard.png

在网上找了好几个方法了,可是还是没解决,求大神帮忙解决。

clipboard.png

clipboard.png

root@dream-virtual-machine:~# sudo apt update
命中 http://archive.ubuntukylin.com:10006 trusty InRelease                     
忽略 http://cn.archive.ubuntu.com trusty InRelease                             
命中 http://cn.archive.ubuntu.com trusty-updates InRelease            
命中 http://archive.ubuntukylin.com:10006 trusty/main Translation-en           
命中 http://cn.archive.ubuntu.com trusty-backports InRelease                   
命中 http://security.ubuntu.com trusty-security InRelease                      
命中 http://archive.ubuntukylin.com:10006 trusty/main amd64 Packages           
命中 http://archive.ubuntukylin.com:10006 trusty/main i386 Packages            
命中 http://cn.archive.ubuntu.com trusty Release.gpg
命中 http://cn.archive.ubuntu.com trusty-updates/main Sources                  
命中 http://cn.archive.ubuntu.com trusty-updates/restricted Sources            
命中 http://security.ubuntu.com trusty-security/main Sources                   
命中 http://cn.archive.ubuntu.com trusty-updates/universe Sources
命中 http://cn.archive.ubuntu.com trusty-updates/multiverse Sources            
命中 http://cn.archive.ubuntu.com trusty-updates/main amd64 Packages           
命中 http://cn.archive.ubuntu.com trusty-updates/restricted amd64 Packages     
命中 http://security.ubuntu.com trusty-security/restricted Sources             
命中 http://cn.archive.ubuntu.com trusty-updates/universe amd64 Packages
命中 http://cn.archive.ubuntu.com trusty-updates/multiverse amd64 Packages     
命中 http://cn.archive.ubuntu.com trusty-updates/main i386 Packages            
命中 http://cn.archive.ubuntu.com trusty-updates/restricted i386 Packages      
命中 http://security.ubuntu.com trusty-security/universe Sources               
命中 http://cn.archive.ubuntu.com trusty-updates/universe i386 Packages
命中 http://cn.archive.ubuntu.com trusty-updates/multiverse i386 Packages      
命中 http://security.ubuntu.com trusty-security/multiverse Sources             
命中 http://cn.archive.ubuntu.com trusty-updates/main Translation-en           
命中 http://cn.archive.ubuntu.com trusty-updates/multiverse Translation-en     
命中 http://cn.archive.ubuntu.com trusty-updates/restricted Translation-en     
命中 http://security.ubuntu.com trusty-security/main amd64 Packages            
命中 http://cn.archive.ubuntu.com trusty-updates/universe Translation-en
命中 http://cn.archive.ubuntu.com trusty-backports/main Sources         
命中 http://cn.archive.ubuntu.com trusty-backports/restricted Sources   
命中 http://security.ubuntu.com trusty-security/restricted amd64 Packages      
命中 http://cn.archive.ubuntu.com trusty-backports/universe Sources            
命中 http://cn.archive.ubuntu.com trusty-backports/multiverse Sources          
命中 http://cn.archive.ubuntu.com trusty-backports/main amd64 Packages         
命中 http://security.ubuntu.com trusty-security/universe amd64 Packages        
命中 http://cn.archive.ubuntu.com trusty-backports/restricted amd64 Packages   
命中 http://cn.archive.ubuntu.com trusty-backports/universe amd64 Packages     
命中 http://cn.archive.ubuntu.com trusty-backports/multiverse amd64 Packages   
命中 http://cn.archive.ubuntu.com trusty-backports/main i386 Packages          
命中 http://security.ubuntu.com trusty-security/multiverse amd64 Packages      
命中 http://cn.archive.ubuntu.com trusty-backports/restricted i386 Packages    
命中 http://cn.archive.ubuntu.com trusty-backports/universe i386 Packages      
命中 http://cn.archive.ubuntu.com trusty-backports/multiverse i386 Packages    
命中 http://security.ubuntu.com trusty-security/main i386 Packages             
命中 http://cn.archive.ubuntu.com trusty-backports/main Translation-en         
命中 http://cn.archive.ubuntu.com trusty-backports/multiverse Translation-en
命中 http://cn.archive.ubuntu.com trusty-backports/restricted Translation-en   
命中 http://security.ubuntu.com trusty-security/restricted i386 Packages       
命中 http://cn.archive.ubuntu.com trusty-backports/universe Translation-en     
命中 http://cn.archive.ubuntu.com trusty Release                               
命中 http://cn.archive.ubuntu.com trusty/main Sources                          
命中 http://security.ubuntu.com trusty-security/universe i386 Packages
命中 http://cn.archive.ubuntu.com trusty/restricted Sources                   
命中 http://cn.archive.ubuntu.com trusty/universe Sources                     
命中 http://cn.archive.ubuntu.com trusty/multiverse Sources                    
命中 http://security.ubuntu.com trusty-security/multiverse i386 Packages       
命中 http://cn.archive.ubuntu.com trusty/main amd64 Packages                   
命中 http://cn.archive.ubuntu.com trusty/restricted amd64 Packages             
命中 http://cn.archive.ubuntu.com trusty/universe amd64 Packages               
命中 http://cn.archive.ubuntu.com trusty/multiverse amd64 Packages             
命中 http://security.ubuntu.com trusty-security/main Translation-en
命中 http://cn.archive.ubuntu.com trusty/main i386 Packages                    
命中 http://cn.archive.ubuntu.com trusty/restricted i386 Packages              
命中 http://security.ubuntu.com trusty-security/multiverse Translation-en
命中 http://cn.archive.ubuntu.com trusty/universe i386 Packages
命中 http://cn.archive.ubuntu.com trusty/multiverse i386 Packages
命中 http://cn.archive.ubuntu.com trusty/main Translation-zh_CN
命中 http://security.ubuntu.com trusty-security/restricted Translation-en
命中 http://cn.archive.ubuntu.com trusty/main Translation-en                 
命中 http://cn.archive.ubuntu.com trusty/multiverse Translation-zh_CN        
命中 http://security.ubuntu.com trusty-security/universe Translation-en        
命中 http://cn.archive.ubuntu.com trusty/multiverse Translation-en             
命中 http://cn.archive.ubuntu.com trusty/restricted Translation-zh_CN          
命中 http://cn.archive.ubuntu.com trusty/restricted Translation-en             
命中 http://cn.archive.ubuntu.com trusty/universe Translation-zh_CN            
命中 http://cn.archive.ubuntu.com trusty/universe Translation-en               
忽略 http://cn.archive.ubuntu.com trusty/main Translation-zh                   
忽略 http://cn.archive.ubuntu.com trusty/multiverse Translation-zh             
忽略 http://cn.archive.ubuntu.com trusty/restricted Translation-zh             
忽略 http://cn.archive.ubuntu.com trusty/universe Translation-zh               
正在读取软件包列表... 完成 
root@dream-virtual-machine:~# sudo apt install -f
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
正在更正依赖关系... 完成
下列软件包是自动安装的并且现在不需要了:
  diffstat gettext hardening-includes intltool-debian libapt-pkg-perl
  libarchive-zip-perl libasprintf-dev libauthen-sasl-perl libautodie-perl
  libclass-accessor-perl libclone-perl libdigest-hmac-perl libemail-valid-perl
  libgettextpo-dev libio-pty-perl libio-socket-inet6-perl
  libio-socket-ssl-perl libio-string-perl libipc-run-perl
  libipc-system-simple-perl liblist-moreutils-perl libmailtools-perl
  libnet-dns-perl libnet-domain-tld-perl libnet-ip-perl libnet-libidn-perl
  libnet-smtp-ssl-perl libnet-ssleay-perl libparse-debianchangelog-perl
  libperlio-gzip-perl libsocket6-perl libsub-identify-perl libsub-name-perl
  libtext-levenshtein-perl liburi-perl patchutils t1utils
Use 'apt-get autoremove' to remove them.
将会安装下列额外的软件包:
  python-pkg-resources
建议安装的软件包:
  python-distribute-doc
下列软件包将被升级:
  python-pkg-resources
升级了 1 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 582 个软件包未被升级。
有 36 个软件包没有被完全安装或卸载。
需要下载 0 B/61.9 kB 的软件包。
解压缩后会消耗掉 0 B 的额外空间。
您希望继续执行吗? [Y/n] y
(正在读取数据库 ... 系统当前共安装有 146983 个文件和目录。)
Preparing to unpack .../python-pkg-resources_3.3-1ubuntu2_all.deb ...
  File "/usr/bin/pyclean", line 63
    except (IOError, OSError), e:
                             ^
SyntaxError: invalid syntax
dpkg:警告:子进程 旧的 pre-removal 脚本 返回了错误号 1
dpkg: trying script from the new package instead ...
  File "/usr/bin/pyclean", line 63
    except (IOError, OSError), e:
                             ^
SyntaxError: invalid syntax
dpkg: error processing archive /var/cache/apt/archives/python-pkg-resources_3.3-1ubuntu2_all.deb (--unpack):
 子进程 新的 pre-removal 脚本 返回了错误号 1
Traceback (most recent call last):
  File "/usr/bin/pycompile", line 35, in <module>
    from debpython.version import SUPPORTED, debsorted, vrepr, \
  File "/usr/share/python/debpython/version.py", line 24, in <module>
    from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
dpkg:清理时出错:
 子进程 已安装 post-installation 脚本 返回了错误号 1
在处理时有错误发生:
 /var/cache/apt/archives/python-pkg-resources_3.3-1ubuntu2_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
root@dream-virtual-machine:~# sudo apt install -y python-pip python3-pip
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
python-pip 已经是最新的版本了。
您可能需要运行“apt-get -f install”来纠正下列错误:
下列软件包有未满足的依赖关系:
 python-setuptools : 依赖: python-pkg-resources (= 3.3-1ubuntu2) 但是 3.3-1ubuntu1 正要被安装
 python3-pip : 依赖: python3-colorama 但是它将不会被安装
               依赖: python3-distlib 但是它将不会被安装
               依赖: python3-html5lib 但是它将不会被安装
               依赖: python3-setuptools 但是它将不会被安装
               推荐: python3-dev (>= 3.2) 但是它将不会被安装
               推荐: python3-wheel 但是它将不会被安装
E: 有未能满足的依赖关系。请尝试不指明软件包的名字来运行“apt-get -f install”(也可以指定一个解决办法)。
阅读 6.7k
4 个回答

你装完python 3应该自带pip了吧。。。

sudo apt update
sudo apt install -f
sudo apt install -y python-pip python3-pip

打完收工

  1. 他既然说你安装了Python-pip,我建议你先

    which python
    which pip

    看一下你装没装上,装上了不成功和没装上的情况不太一样的。

  2. 确定没装pip且有Python3的话(现在Ubuntu应该只预装Python3了吧)。

    apt-get install python3-setuptools
    # 然后
    easy_install3 pip
  3. 你在root下,没必要sudo。而且root下挺危险的,看你也不熟Linux。建议建一个在superuser group里的用户,到那个用户里用sudo执行命令。
新手上路,请多包涵

ubuntu那么矫情的系统,你破坏python的关系啦,删除你的soft link,重新建立回python2。然后按照2楼的回复,估计你就成了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题