1

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

JJ Hassan
  • 395
  • 3
  • 11
Mouin
  • 1,025
  • 4
  • 19
  • 33
  • This isn't actually a python question. It's to do with the way Linux parses shebang lines, which doesn't work with alias' as shown in this answer https://serverfault.com/a/1050710 The repo file starts with `#!/usr/bin/env python` and the line at which it is failing is a buggy error that uses python3 syntax to alert the user that they're using python2. Not your fault that this wasn't clear! – JJ Hassan Feb 08 '21 at 17:46

1 Answers1

0

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.
JJ Hassan
  • 395
  • 3
  • 11
  • 1
    As indicated in the error message, it comes from a different file which presumably does not have this `import`. Brief experimentation reveals that `repo` ends up trying to call `python` as a subprocess of itself and/or `exec` it. – tripleee Feb 09 '21 at 06:21
  • @tripleee Good point, I'd for some reason assumed it was just unpacked from that file. Could you share what your experimentation was? Checking running processes or something? – JJ Hassan Feb 09 '21 at 09:52
  • I just tried to run it, and got an error message about Python being unavailable, probably because it somehow failed to anticipate my use of `pyenv`. – tripleee Feb 09 '21 at 09:54