Search code examples
pythonshellrepo

repo SyntaxError: invalid syntax


I run the following commands to get repo:

mkdir ~/bin
curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
PATH=${PATH}:~/bin

I have 2 python versions(2.7 and 3.7) in my computer so I created an alias to python3 in ~/.bashrc because this is required by repo

alias python=python3

Then run following commands to get the yocto project:

repo init -u https://xxxx -b release/bxxx

I got this error:

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

if I run python3 ~/bin/repo init -u https:/blablabla there is no problem, so some how executing the first command calls to python2. Any explanation


Solution

  • Two points to the explanation you're looking for:

    1. Your alias isn't being used when your OS looks for an interpreter to execute the repo file. It starts with the shebang line #!/usr/bin/env python which might be pointing to python 2.7 on your machine. Try just writing /usr/bin/env python on your terminal and seeing which version of python console is launched. See this answer for suggestions.
    2. I think the reason you're getting this syntax error is because you are indeed using python2.7 and the repo file's import from __future__ import print_function doesn't seem to be working as expected (which would make that syntax okay). Not sure why that's happening though.