SyntaxError:在AOSP代码中repoinit的语法无效
我曾尝试 repo init 源代码 Ubuntu 构建机器,它能够成功克隆代码。
回购初始化 -u git@github.com:xxx/xx_manifest.git -b xxx
现在我正在尝试 repo init VM Ubuntu 机器中的源代码。
在得到如下错误之间:
Traceback (most recent call last):
File "/xxx/.repo/repo/main.py", line 56, in <module>
from subcmds.version import Version
File "/xxx/.repo/repo/subcmds/__init__.py", line 38, in <module>
['%s' % name])
File "/xxx/.repo/repo/subcmds/upload.py", line 27, in <module>
from hooks import RepoHook
File "/xxx/.repo/repo/hooks.py", line 472
file=sys.stderr)
^
SyntaxError: invalid syntax
python 版本在构建机器和 vm 机器 2.7.17 中是相同的。
回答
试试这些命令
curl https://storage.googleapis.com/git-repo-downloads/repo-1 > ~/bin/repo
chmod a+x ~/bin/repo
python3 ~/bin/repo init -u git@....
- Welcome to StackOverflow! Here are some tips to help you write better answers: Answers which simply contain code snippets or commands without an explanation on what they do / why/how they would solve the OP's question are unlikely to be accepted or receive upvotes. The best answers are ones which thoroughly explain how and why they work, step-by-step, with formatting (bold/italic/underline/headings) to improve readability, along with good grammar and spelling (such as capitalising the first word in each sentence). You can also edit your answer at any time if you want to improve it 🙂
回答
我刚刚遇到了同样的问题,这为我解决了:
- 下载最新版本的 repo :
curl https://storage.googleapis.com/git-repo-downloads/repo-1 > repo - 更改权限以使其可执行:
chmod a+x repo - 使用 python3 和您刚刚下载的“repo”运行您的 repo init:
python3 repo init -u git@github.com:xxx/xx_manifest.git -b xxx
回答
在使用以下命令安装 OpenSTLinux Yocto 层期间,我在 Ubuntu 18.04 上遇到了同样的问题:
repo init -u https://github.com/STMicroelectronics/oe-manifest.git -b refs/tags/openstlinux-5.4-dunfell-mp1-20-11-12
返回:
Get https://gerrit.googlesource.com/git-repo/clone.bundle
Get https://gerrit.googlesource.com/git-repo
remote: Counting objects: 2, done
remote: Finding sources: 100% (117/117)
remote: Total 117 (delta 63), reused 117 (delta 63)
Receiving objects: 100% (117/117), 142.25 KiB | 11.85 MiB/s, done.
Resolving deltas: 100% (63/63), completed with 32 local objects.
From https://gerrit.googlesource.com/git-repo
1469c28..0588f3d main -> origin/main
* [new tag] v2.11 -> v2.11
* [new tag] v2.11.1 -> v2.11.1
Traceback (most recent call last):
File "/home/xxx/Distribution-Package/openstlinux-5.4-dunfell-mp1-20-11-12/.repo/repo/main.py", line 56, in <module>
from subcmds.version import Version
File "/home/xxx/Distribution-Package/openstlinux-5.4-dunfell-mp1-20-11-12/.repo/repo/subcmds/__init__.py", line 38, in <module>
['%s' % name])
File "/home/xxx/Distribution-Package/openstlinux-5.4-dunfell-mp1-20-11-12/.repo/repo/subcmds/upload.py", line 27, in <module>
from hooks import RepoHook
File "/home/xxx/Distribution-Package/openstlinux-5.4-dunfell-mp1-20-11-12/.repo/repo/hooks.py", line 472
file=sys.stderr)
这个问题随着使用 Python3 而不是 Python (2.7) 消失。你可以这样做:
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3 /usr/bin/python