'Python SyntaxError invalid syntax Error While Repo Init

When i run

sudo repo init -u https://github.com/LineageOS/android.git -b lineage-18.1

I am getting error -

 File "/home/rahul/android/lineage/.repo/repo/main.py", line 79
    file=sys.stderr)
        ^ SyntaxError: invalid syntax

if i run above command without sudo, i am getting following error -

/snap/git-repo/18/usr/bin/python: can't open file '/home/rahul/android/lineage/.repo/repo/main.py': [Errno 13] Permission denied

I am having python3 on my system.

Any idea how to fix?



Solution 1:[1]

Could you please check the version of repo by using the repo --version command on your terminal and try reinstalling the repo package? Maybe the issue with the version.

repo version v2.21
       (from https://gerrit.googlesource.com/git-repo)
       (tracking refs/heads/stable)
       (Wed, 26 Jan 2022 16:46:03 +0000)
repo launcher version 2.21
       (from /usr/local/bin/repo)
       (currently at 2.21)
repo User-Agent git-repo/2.21 (Darwin) git/2.31.1 Python/3.10.2
git 2.31.1
git User-Agent git/2.31.1 (Darwin) git-repo/2.21
Python 3.10.2 (main, Feb  2 2022, 07:36:01) [Clang 12.0.0 (clang-1200.0.32.29)]
OS Darwin 20.6.0 (Darwin Kernel Version 20.6.0: Wed Jan 12 22:22:42 PST 2022; root:xnu-7195.141.19~2/RELEASE_X86_64)
CPU x86_64 (i386)

If on mac: try brew reinstall repo as it should work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SMRITI MAHESHWARI