python 2.7.3(ubuntu12.04 default python) 升级到 python 2.7.6 版本的方法

android 代码编译时遇到如下问题需要将 ubuntu 下 python2.7.3 升级到 python 2.7.6 及以上。

[100% 109208/109208] Target vbmeta image: out/target/product/lotus/vbmeta.img
FAILED: out/target/product/lotus/vbmeta.img 
/bin/bash -c "(mkdir -p out/target/product/lotus/obj/avb_chain_keys ) && (out/host/linux-x86/bin/avbtool make_vbmeta_image --include_descriptors_from_image out/target/product/lotus/boot.img --include_descriptors_from_image out/target/product/lotus/system.img --include_descriptors_from_image out/target/product/lotus/vendor.img --include_descriptors_from_image out/target/product/lotus/recovery.img --algorithm SHA256_RSA2048 --key device/xiaomi/lotus/oemprvk.pem --padding_size 4096 --output out/target/product/lotus/vbmeta.img ) && (rm -rf out/target/product/lotus/obj/avb_chain_keys )"
Traceback (most recent call last):
  File "out/host/linux-x86/bin/avbtool", line 3931, in <module>
    tool.run(sys.argv)
  File "out/host/linux-x86/bin/avbtool", line 3797, in run
    args.func(args)
  File "out/host/linux-x86/bin/avbtool", line 3825, in make_vbmeta_image
    args.padding_size)
  File "out/host/linux-x86/bin/avbtool", line 2402, in make_vbmeta_image
    append_to_release_string)
  File "out/host/linux-x86/bin/avbtool", line 2549, in _generate_vbmeta_blob
    (_, _, image_descriptors, _) = self._parse_image(image_handler)
  File "out/host/linux-x86/bin/avbtool", line 2223, in _parse_image
    descriptors = parse_descriptors(image.read(h.descriptors_size))
  File "out/host/linux-x86/bin/avbtool", line 1731, in parse_descriptors
    ret.append(c(bytearray(data[o:o + 16 + nb_following])))
  File "out/host/linux-x86/bin/avbtool", line 1403, in __init__
    digest_len, _) = struct.unpack(self.FORMAT_STRING, data[0:self.SIZE])
struct.error: unpack requires a string argument of length 132
ninja: build stopped: subcommand failed.
13:54:14 ninja failed with: exit status 1

#### failed to build some targets (04:14:02 (hh:mm:ss)) ####

解决方法:

1. 下载并安装 python 2.7.6

$su root
#cd /usr/local
#wget https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
#tar -zxvf Python-2.7.6.tgz && cd Python-2.7.6 && ./configure && make all && make install && make clean && make distclean

2. 建立软连接

#mv /usr/bin/python /usr/bin/python2.7.3  // 备份系统python,万一出错可以复原
#ln -s /usr/local/bin/python2.7 /usr/bin/python  // 将新安装的 python 2.7.6 建立软连接到 python
#python -V  // 查看现在使用的 python 版本是否符合

3. 此时使用#pip 看是否可用,如可用则 python 已安成功。如报错:

ImportError: No module named 'pkg_resources'

这是因为 python 升级带来的问题。

解决方案:

1. 安装 distribute

#cd /usr/local
#wget https://pypi.python.org/packages/source/d/distribute/distribute-0.7.3.zip --no-check-certificate
#unzip distribute-0.7.3.zip
#cd distribute-0.7.3
#python setup.py install

2. 安装 setuptool

https://pypi.python.org/pypi/setuptools  下载最新版

#cd setuptools-xxx 
#python setup.py install

3. 安装 pip

#easy_install pip
#pip -V

显示 pip 版本,即 pip 可以使用了。

猜你喜欢

转载自www.cnblogs.com/whz666/p/9991181.html