简体   繁体   English

SyntaxError:AOSP 代码中 repo init 的语法无效

[英]SyntaxError: invalid syntax to repo init in the AOSP code

I have tried to repo init the source code Ubuntu build machine and it is successfully able to clone the code.我尝试重新初始化源代码 Ubuntu 构建机器,它成功地克隆了代码。

repo init -u git@github.com:xxx/xx_manifest.git -b xxx回购初始化-u git@github.com:xxx/xx_manifest.git-b xxx

Now I am trying repo init the source code in VM Ubuntu machine.现在我正在尝试 repo 初始化 VM Ubuntu 机器中的源代码。

In between getting the error like below:在出现如下错误之间:

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 version is same in build machine and vm machine 2.7.17. python 构建机和虚拟机 2.7.17 中的版本相同。

try these commands试试这些命令

curl https://storage.googleapis.com/git-repo-downloads/repo-1 > ~/bin/repo
chmod a+x ~/bin/repo
python3 ~/bin/repo init -u git@....

I just had the same issue and this resolved it for me:我刚刚遇到了同样的问题,这为我解决了:

  • Download last version of repo: curl https://storage.googleapis.com/git-repo-downloads/repo-1 > repo下载最新版本的 repo: curl https://storage.googleapis.com/git-repo-downloads/repo-1 > repo
  • Change right to make it executable: chmod a+x repo更改权限以使其可执行: chmod a+x repo
  • Run your repo init with python3 and the "repo" you just download: python3 repo init -u git@github.com:xxx/xx_manifest.git -b xxx使用 python3 和您刚刚下载的“repo”运行您的 repo init: python3 repo init -u git@github.com:xxx/xx_manifest.git -b xxx

I have experienced the same issue on Ubuntu 18.04 during the installation of the OpenSTLinux Yocto layer with the following command:在使用以下命令安装 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

Returns:退货:

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)

This issue goes away with using Python3 instead of Python (2.7).使用 Python3 而不是 Python (2.7) 会解决此问题。 You can do this:你可以这样做:

sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3 /usr/bin/python

Try below command to make it will work 100%, tried & suggested尝试以下命令,使其 100% 正常工作,已尝试并建议

mkdir -p ~/.bin
PATH="${HOME}/.bin:${PATH}"
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/.bin/repo
chmod a+rx ~/.bin/repo

One solution is to modify the first line of /usr/bin/repo and change it from一种解决方案是修改 /usr/bin/repo 的第一行并将其更改为

#!/usr/bin/python

to

#!/usr/bin/python3

This asks the system to use Python3 instead of the default Python.这要求系统使用 Python3 而不是默认的 Python。

If the system you are running on doesn't have python3, like in my case, and you don't have the option to install python3, or installing it breaks other parts, the option is the degrade repo to a version that uses python2.7:如果您运行的系统没有 python3,就像我的情况一样,并且您没有安装 python3 的选项,或者安装它会破坏其他部分,则选项是将 repo 降级到使用 python2 的版本。 7:

- git clone https://gerrit.googlesource.com/git-repo
- cd git-repo
- git reset --hard v1.13.11
- mkdir -p ~/.bin
- PATH="${HOME}/.bin:${PATH}"
- cp repo ~/.bin/repo
- chmod a+rx ~/.bin/repo

This will use v1.13.11 of repo, which works with python2.7这将使用 repo 的 v1.13.11,它适用于 python2.7

As seen in a similar error in arvestad/alv issue 1 , that would be consistent with running the process with Python 2.7 instead of Python3正如在arvestad/alv问题 1中的类似错误中看到的那样,这与使用 Python 2.7 而不是 Python3 运行该过程是一致的

Double-check you Python version between:仔细检查您的 Python 版本:

  • your Ubuntu build machine (where the repo init works)你的 Ubuntu 构建机器( repo init工作的地方)
  • your VM Ubuntu machine (where the repo init fails)您的 VM Ubuntu 机器( repo init失败的地方)

Same error here , with the error suggesting you are executing python2 with a PYTHONPATH that's only appropriate for python3 .这里出现同样的错误,错误提示您正在使用仅适用于python3PYTHONPATH执行python2

I don't know exactly how this works, but i just had the same issue and this resolved it for me it seems.我不知道这是如何工作的,但我遇到了同样的问题,这似乎为我解决了。

https://source.android.com/setup/develop#installing-repo Dont use the legacy one, use the first one to resolve it. https://source.android.com/setup/develop#installing-repo不要用旧的,用第一个解决。

Edit: It seems you also need to have python 3.6 installed on you system to have this work.编辑:看来您还需要在系统上安装 python 3.6 才能进行这项工作。 You can still have update-alternatives point to python 2.7, you simply need 3.6 or newer installed.你仍然可以让 update-alternatives 指向 python 2.7,你只需要安装 3.6 或更新版本。

Just install python3 and the latest repo.只需安装 python3 和最新的 repo。

I encountered the problem too, but on Mac OS.我也遇到了这个问题,但是在 Mac OS 上。 The log is exactly the same as yours.日志和你的完全一样。 Definitely python2 caused this problem.肯定是 python2 导致了这个问题。 repo is try to run python3 files in python2 environment. repo 是尝试在 python2 环境中运行 python3 文件。

I found the this from repo docs https://gerrit.googlesource.com/git-repo/+/refs/heads/master/docs/python-support.md我从回购文档https://gerrit.googlesource.com/git-repo/+/refs/heads/master/docs/python-support.md中找到了这个

So I update my repo (which located in depot_tools).所以我更新了我的仓库(位于 depot_tools 中)。 Since I already have python3 installed, everything is ok now.由于我已经安装了python3,所以现在一切正常。

Hope my experience may help you.希望我的经历可以帮到你。

I have tried to repo init the source code Ubuntu build machine and it is successfully able to clone the code.我已经尝试 repo 初始化源代码 Ubuntu 构建机器,它能够成功克隆代码。

repo init -u git@github.com:xxx/xx_manifest.git -b xxx repo init -u git@github.com:xxx/xx_manifest.git -b xxx

Now I am trying repo init the source code in VM Ubuntu machine.现在我正在尝试 repo init VM Ubuntu 机器中的源代码。

In between getting the error like below:在出现如下错误之间:

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 version is same in build machine and vm machine 2.7.17. python 版本在 build machine 和 vm machine 2.7.17 中是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM