close

SyntaxError: invalid syntax to repo init in the AOSP code

Hello guys how are you all ? Hope you all are fine. when I was clone my repo and clone successfully when i tryied repo init the source code in VM ubuntu machine I wsa found this error. SyntaxError: invalid syntax to repo init in the AOSP code

So Here is I am come with all possible solution to solve this error. So without wasting your time. Lets start this article.

What is Error ?

When I try repo init the source code I was found this error

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

Solutions

Question : SyntaxError: Invalid syntax to repo init in the AOSP code

Answer : The problem is I think python version. So run the repo init with python3 and the repo you just downloaded will solve your problem.

Solution 1

The problem is I think python version. So run the repo init with python3 and the repo you just downloaded will solve your problem.

Just Follow below Command

  1. curl https://storage.googleapis.com/git-repo-downloads/repo-1 > ~/bin/repo
  2. chmod a+x ~/bin/repo
  3. python3 ~/bin/repo init -u [email protected]….

This will solve your issue.

Solution 2

To Solve this issue follow below steps

  1. Download last version of repo : curl https://storage.googleapis.com/git-repo-downloads/repo-1 > repo
  2. Change right to make it executable : chmod a+x repo
  3. Run your repo init with python3 and the “repo” you just download : python3 repo init -u [email protected]:xxx/xx_manifest.git -b xxx

Solution 3

Double-check you Python version between:

  • your Ubuntu build machine (where the repo init works)
  • your VM Ubuntu machine (where the repo init fails)

Check here Same error here, with the error suggesting you are executing python2 with a PYTHONPATH that’s only appropriate for python3.

Solution 4

Just modify the first line of /usr/bin/repo and change it from

#!/usr/bin/python

to

#!/usr/bin/python3

This asks the system to use Python3 instead of the default Python.

Summery

So it’s all About this issue. Hope SyntaxError: invalid syntax to repo init in the AOSP code above all solution helped you a lot. Comment below Your thoughts and your queries. And Also Comment on your suggestion here.

Also Read