ubuntu 安装python3 pip 曲折经历

以前一直在ubuntu14.04的python2.7上写selenium.最近想学习一下web接口测试,并且尝试一下python3,所以准备装个djongo玩一下。结果为了安装python3下的pip折腾了一晚上终于工作正常。ubuntu 14.04自带python2.7 和3.4,遂利用apt-get安装pip

sudo apt-get install python3-pip

可是出现类似如下错误(引用自stackoverflow,当时的错误信息没有保存),看信息应该是依赖的setuptools 没有安装,便继续安装setuptools

Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: python-pip : Depends: python-setuptools (>= 0.6c1) but it is not going to be installed Recommends: python-dev-all (>= 2.6) but it is not installable E: Unable to correct problems, you have held broken packages

sudo apt-get install python3 -setuptools

依然出现缺失依赖的错误

Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: python-setuptools : Depends: python-pkg-resources (= 3.3-1ubuntu1) but 3.3-1ubuntu2 is to be installed E: Unable to correct problems, you have held broken packages.

既然提示很明确就继续装呗

sudo apt-get install python-pkg-resources=3.3-1ubuntu1 sudo apt-get install python-setuptools

终于不再报错了,安装pip也正常,并且成功安装了djongo。可是无意间用pip3 freeze 时竟然抛错,而且除了install 其他的几乎都不工作。

Exception: Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main status = self.run(options, args) File "/usr/lib/python2.7/dist-packages/pip/commands/list.py", line 80, in run self.run_listing(options) File "/usr/lib/python2.7/dist-packages/pip/commands/list.py", line 142, in run_listing self.output_package_listing(installed_packages) File "/usr/lib/python2.7/dist-packages/pip/commands/list.py", line 151, in output_package_listing if dist_is_editable(dist): File "/usr/lib/python2.7/dist-packages/pip/util.py", line 348, in dist_is_editable req = FrozenRequirement.from_dist(dist, []) File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 236, in from_dist assert len(specs) == 1 and specs[0][0] == '==' AssertionError

这下有点蒙,搜了一下说是因为pip版本太老,需要升级版本,那就升呗。没想到又是一个大坑啊!

sudo pip3 install --upgrade pip

本来以为一切搞定了,没想到pip直接就挂了。一运行pip3就抛错version confilict

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 654, in _build_master
    ws.require(__requires__)
  File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 968, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py", line 859, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.VersionConflict: (pip 9.0.1 (/usr/local/lib/python3.4/dist-packages), Requirement.parse('pip==7.1.0'))

很明显pkg_resource对应的pip version 是7.1.0, 而我更新后变成了9.0.1,对应不起来所以抛了错。会想到在更新pip的时候有多次timeout的情况,不知道是不是因为安装的中断造成的。找了好久,终于在万能的stackoverflow上找到了办法如下。其实很简单就是再重装一遍pip。至此终于把pip的环境搞定。

sudo python -m pip install --upgrade --force-reinstall pip

    原文作者:cjeric
    原文地址: https://blog.csdn.net/cjeric/article/details/71104445
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞