#昊鼎王五:安装 ./bkcec install paas报错时的解决方案(编码导致的问题)
关键词:蓝鲸智云 安装 报错
#1.报错信息:
install失败报install pbr failed
报错信息如下:
byte-compiling build/bdist.linux-x86_64/egg/pip/_vendor/html5lib/treewalkers/etree.py to etree.pyc
File "build/bdist.linux-x86_64/egg/pip/_vendor/html5lib/treewalkers/etree.py", line 13
from pip._vendor. import string_types
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/pip-9.0.0-py2.7.egg/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/local/lib/python2.7/site-packages/pip-9.0.0-py2.7.egg/pip/commands/install.py", line 272, in run
with self._build_session(options) as session:
File "/usr/local/lib/python2.7/site-packages/pip-9.0.0-py2.7.egg/pip/basecommand.py", line 72, in _build_session
insecure_hosts=options.trusted_hosts,
File "/usr/local/lib/python2.7/site-packages/pip-9.0.0-py2.7.egg/pip/download.py", line 329, in __init__
self.headers["User-Agent"] = user_agent()
File "/usr/local/lib/python2.7/site-packages/pip-9.0.0-py2.7.egg/pip/download.py", line 93, in user_agent
from pip._vendor import distro
File "/usr/local/lib/python2.7/site-packages/pip-9.0.0-py2.7.egg/pip/_vendor/distro.py", line 1051, in
_distro = LinuxDistribution()
File "/usr/local/lib/python2.7/site-packages/pip-9.0.0-py2.7.egg/pip/_vendor/distro.py", line 594, in __init__
if include_lsb else {}
File "/usr/local/lib/python2.7/site-packages/pip-9.0.0-py2.7.egg/pip/_vendor/distro.py", line 922, in _lsb_release_info
stdout, stderr = stdout.decode('ascii'), stderr.decode('ascii')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 22: ordinal not in range(128)
[192.168.1.103]20180411-140404 959 install pbr failed.
#2.定位原因
由于系统编码导致,
默认的是
[root@hd103 pip]# cat /etc/locale.conf
LANG="zh_CN.UTF-8"
[root@hd103 pip]#
#3.解决方案:
##3.1.解决办法
###3.1.1.第一种:这里我们将Python的默认编码方式修改为utf-8,就可以规避上述问题的发生,具体方式,我们在Python文件的前面加上如下代码:
import sys
defaultencoding = 'utf-8'
if sys.getdefaultencoding() != defaultencoding:
reload(sys)
sys.setdefaultencoding(defaultencoding)
###3.1.2第二种:我们在/usr/lib/python2.7/site-packages/目录下添加一个sitecustomize.py文件,内容如下:
import sys
sys.setdefaultencoding('utf-8')
这种方式可以解决所有项目的encoding问题,具体说明可参考/usr/lib/python2.7/site.py文件:
/data/install/pip/pip-9.0.0/build/lib/pip/_vendor/html5lib/treewalkers/etree.py
在首行加上:
import sys
sys.setdefaultencoding('utf-8')
/data/install/pip/pip-9.0.0/build/lib/pip/_vendor/html5lib/treewalkers/etree.py
byte-compiling build/bdist.linux-x86_64/egg/pip/_vendor/html5lib/treewalkers/etree.py to etree.pyc
File "build/bdist.linux-x86_64/egg/pip/_vendor/html5lib/treewalkers/etree.py", line 13
修改前: from pip._vendor. import string_types ---> 修改后: from pip._vendor.six import string_types
vim /data/install/pip/pip-9.0.0/build/lib/pip/_vendor/html5lib/treewalkers/etree.py
###3.1.3.第三种修改方法(改系统语言)
vi /etc/locale.conf
LANG="en_US.UTF-8"
export LANG=en_US.UTF-8
好了,聪明如你,知道了bkcec install paas报错时的解决方案,是不是很欢喜 _