构建Hi3861时报错解决方案

烂漫树林
发布于 2020-11-12 16:21
浏览
1收藏

今天刚刚下载了Hi3861的代码code1.0,按照 环境要求配置好,然后执行构建的时候报错:ImportError: cannot import name 'common_env' from 'scripts'

具体如下

Traceback (most recent call last):

  File "/home/peter/.local/lib/python3.7/site-packages/SCons/Script/Main.py", line 1391, in main

    _exec_main(parser, values)

  File "/home/peter/.local/lib/python3.7/site-packages/SCons/Script/Main.py", line 1355, in _exec_main

    _main(parser)

  File "/home/peter/.local/lib/python3.7/site-packages/SCons/Script/Main.py", line 1029, in _main

    SCons.Script._SConscript._SConscript(fs, script)

  File "/home/peter/.local/lib/python3.7/site-packages/SCons/Script/SConscript.py", line 287, in _SConscript

    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)

  File "/home/peter/work/HarmonyOS/code/vendor/hisi/hi3861/hi3861/SConstruct", line 31, in <module>

    from scripts import common_env

ImportError: cannot import name 'common_env' from 'scripts' (/root/anaconda3/lib/python3.7/site-packages/scripts/__init__.py)


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/home/peter/.local/bin/scons", line 8, in <module>

    sys.exit(main())

  File "/home/peter/.local/lib/python3.7/site-packages/SCons/Script/Main.py", line 1416, in main

    SCons.Script._SConscript.SConscript_exception()

  File "/home/peter/.local/lib/python3.7/site-packages/SCons/Script/SConscript.py", line 349, in SConscript_exception

    stack = traceback.extract_tb(tb)

  File "/root/anaconda3/lib/python3.7/traceback.py", line 72, in extract_tb

    return StackSummary.extract(walk_tb(tb), limit=limit)

  File "/root/anaconda3/lib/python3.7/traceback.py", line 363, in extract

    f.line

  File "/root/anaconda3/lib/python3.7/traceback.py", line 285, in line

    self._line = linecache.getline(self.filename, self.lineno).strip()

  File "/root/anaconda3/lib/python3.7/linecache.py", line 16, in getline

    lines = getlines(filename, module_globals)

  File "/root/anaconda3/lib/python3.7/linecache.py", line 47, in getlines

    return updatecache(filename, module_globals)

  File "/root/anaconda3/lib/python3.7/linecache.py", line 137, in updatecache

    lines = fp.readlines()

  File "/root/anaconda3/lib/python3.7/codecs.py", line 322, in decode

    (result, consumed) = self._buffer_decode(data, self.errors, final)

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xca in position 739: invalid continuation byte

 

打开构建脚本一看,原来是找不到commen_env.py模块,该python文件放在 code/vendor/hisi/hi3861/hi3861/build/scripts/ 目录下,构建脚本是 vendor/hisi/hi3861/hi3861/SConstruct,打开发现问题:

sys.path.append(os.path.join(os.getcwd(), 'build'))

print('------------------',os.getcwd())

print(sys.path)

from scripts import common_env

from scripts import scons_utils

from scripts import scons_app

代码中已经把 build目录添加到sys路径里面了,但是由于scripts目录太过常见,添加的路径太靠后,导致python找到了错误的scripts文件夹(/root/anaconda3/lib/python3.7/site-packages/scripts),解决方法很简单:把append修改为insert即可:

sys.path.insert(0,os.path.join(os.getcwd(), 'build'))

print('------------------',os.getcwd())

print(sys.path)

from scripts import common_env

from scripts import scons_utils


分类
标签
已于2021-7-8 17:38:59修改
2
收藏 1
回复
举报
1条回复
按时间正序
/
按时间倒序
wx590726886001f
wx590726886001f

博主你好,麻烦问下编译脚本怎么打开的

回复
2021-7-12 14:02:03
回复
    相关推荐