Gangmax Blog

在Ubuntu上安装“python-virtualenv/python-pip”出错的解决方法

我今天看到一篇介绍“jip – Jython Pip”的文章,便想试试。按照步骤,需要先安装“python-virtualenv”,直接:

1
sudo apt-get install python-virtualenv

但是运行后有错误,安装失败:

1
2
3
4
5
6
正在解压缩 python-pip (从 .../python-pip_0.3.1-1ubuntu2.1_all.deb) ...
dpkg:处理 /var/cache/apt/archives/python-pip_0.3.1-1ubuntu2.1_all.deb (--unpack)时出错:
正试图覆盖“/usr/bin/pip”,它同时被包含于软件包 pip 0:0.13-1
在处理时有错误发生:
/var/cache/apt/archives/python-pip_0.3.1-1ubuntu2.1_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

从命令行的输出可以看出“python-pip”是“python-virtualenv”所依赖的一个包,因此必须被先安装。安装它的时候就出了上面的错误。运行“apt-get install”也会出错,这可够罕见的。

错误信息里面的这一句引起了我的注意:

1
正试图覆盖“/usr/bin/pip”,它同时被包含于软件包 pip 0:0.13-1

看样子像是系统里面已经安装了一个“pip”,因此在覆盖的时候有错。那就好办了,先看看安装的这个pip是什么东东:

1
apt-cache show pip

果然有内容,输出是:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Package: pip
Priority: optional
Section: universe/perl
Installed-Size: 112
Maintainer: Ubuntu Developers <ubuntu -devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Perl Group <pkg -perl-maintainers@lists.alioth.debian.org>
Architecture: all
Version: 0.13-1
Depends: perl, liburi-perl, libfile-pushd-perl, libfile-which-perl, libparams-util-perl (>= 0.21), libcpan-inject-perl, libwww-perl
Filename: pool/universe/p/pip/pip_0.13-1_all.deb
Size: 20328
MD5sum: 8f09790dcae9b19a5d718b6ec3023996
SHA1: 91fae661f4cde228e447ebfaadec4a5298c2377d
SHA256: c42c00268a9a3aca4ea4672b4f291b0e7089ef42002aea5f94443d560661cb90
Description: tool for scripted and third-party CPAN distribution installation
pip is the Perl Installation Program, for installation of scripted and
third-party distributions. It can be given a local or remote tarball, which
it will inject into your local CPAN sources. The CPAN Shell is then used to
install it in the same way you would install distributions from CPAN.
Homepage: http://search.cpan.org/dist/pip/
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu

原来Ubuntu系统自带的pip是Perl语言的包管理工具,和“python-pip”中的pip命令重名了,所以就会有前文出现的错误。因为我不使用Perl,那我就删除之再安装:

1
2
3
4
sudo apt-get remove pip
#There's several packages depends only used by pip, they can be removed when pip is removed.
sudo apt-get autoremove
sudo apt-get install python-virtualenv

这次就一切正常了。

Comments