我正在运行默认使用 python 2.7 的 Ubuntu 12.10。我已经在 /opt/python3.3 中安装了 python 3.3(使用 ./configure --prefix=/opt/python3.3)并创建了一个符号链接 /usr/bin/python33 指向 /opt 中的可执行文件。已经有一个符号链接 /usr/bin/python3 指向 python 3.2(实际上它指向 python3.2mu:如果你可以解释一下为什么包含这个'mu' :))安装附带ubuntu 安装。我使用 python3 安装了分发工具,没有任何问题。但是当我用 python33 尝试同样的事情时,它给了我以下错误:
ankur@junk-mechanism:~$ sudo python33 distribute_setup.py
Extracting in /tmp/tmp685lyf
lzma module is not available
not a bzip2 file
gzip module is not available
bad checksum
Traceback (most recent call last):
File "distribute_setup.py", line 550, in <module>
sys.exit(main())
File "distribute_setup.py", line 547, in main
return _install(tarball, _build_install_args(options))
File "distribute_setup.py", line 78, in _install
tar = tarfile.open(tarball)
File "/opt/python3.3/lib/python3.3/tarfile.py", line 1578, in open
raise ReadError("file could not be opened successfully" + str(name) + repr(fileobj))
tarfile.ReadError: file could not be opened successfully/home/ankur/distribute-0.6.35.tar.gzNone
所以在 tarfile.py 中,类方法 Tarfile.open 调用了导入模块 gzip 的类方法 Tarfile.gzopen:
try:
import gzip
gzip.GzipFile
except (ImportError, AttributeError):
raise CompressionError("gzip module is not available")
此处引发的错误是 ImportError,因为 gzip.py 有一个无法找到的导入 zlib。但即使是其他安装的 python(2.7 和 3.2)也不在各自的标准库 /usr/lib/pythonx.x/lib/ 中包含 zlib。那么区别是什么呢?