Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have tried to repo init the source code Ubuntu build machine and it is successfully able to clone the code.

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.

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.

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@....
                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 :)
– Someguy123
                Dec 8, 2020 at 18:53
                run the following commands before these: 1. mkdir -p ~/.bin after this run  2. PATH="${HOME}/.bin:${PATH}"  enjoy
– Ali Waqas
                Jul 31, 2021 at 19:21
  • Download last version of repo : curl https://storage.googleapis.com/git-repo-downloads/repo-1 > repo
  • Change right to make it executable : 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
  • This is the same as the accepted answer but with explanation. An edit on the accepted answer would be better, but @skrrt isn't changing anything, so I'm upvoting this over the accepted – Daniel C Jacobs Jan 13, 2022 at 20:12

    I have experienced the same issue on Ubuntu 18.04 during the installation of the OpenSTLinux Yocto layer with the following command:

    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). 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

    mkdir -p ~/.bin
    PATH="${HOME}/.bin:${PATH}"
    curl https://storage.googleapis.com/git-repo-downloads/repo > ~/.bin/repo
    chmod a+rx ~/.bin/repo
                    definitely a solid answer... matches the docs exactly gerrit.googlesource.com/git-repo/#install
    – BushMinusZero
                    Jun 15, 2022 at 1:28
    

    One solution is to modify the first line of /usr/bin/repo and change it from

    #!/usr/bin/python
    
    #!/usr/bin/python3
    

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

    I am surprised I am the first one to up vote this. It works perfectly and requires the least work. – Kent Tong Oct 26, 2021 at 7:44

    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:

    - 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

    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

    Double-check you Python version between:

  • your Ubuntu build machine (where the repo init works)
  • your VM Ubuntu machine (where the repo init fails)
  • Same error here, with the error suggesting you are executing python2 with a PYTHONPATH that's only appropriate for python3.

    There must be a difference though, since the error means you are using a python2 instead of 3. Check your environment variables (PYTHONPATH for example) – VonC Dec 8, 2020 at 9:23

    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.

    Edit: It seems you also need to have python 3.6 installed on you system to have this work. You can still have update-alternatives point to python 2.7, you simply need 3.6 or newer installed.

    Just install python3 and the latest repo.

    I encountered the problem too, but on Mac OS. The log is exactly the same as yours. Definitely python2 caused this problem. repo is try to run python3 files in python2 environment.

    I found the this from repo docs https://gerrit.googlesource.com/git-repo/+/refs/heads/master/docs/python-support.md

    So I update my repo (which located in depot_tools). Since I already have python3 installed, everything is ok now.

    Hope my experience may help you.