iamandi / nanopb

Automatically exported from code.google.com/p/nanopb
zlib License
0 stars 0 forks source link

nanopb_generator.py fails on systems with python3 as default interpreter #155

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. python3 is set as default instead python2
2. protoc --plugin=protoc-gen-nanopb=nanopb/generator/protoc-gen-nanopb ... 
fails by "old" exception syntax: except Exception, e:

What is the expected output? What do you see instead?
 File "nanopb/generator/nanopb_generator.py", line 1189
    except Exception, e:
                    ^
SyntaxError: invalid syntax
--nanopb_out: protoc-gen-nanopb: Plugin failed with status code 1.

What version of the product are you using? On what operating system?
- Arch Linux
- nanopb-0.3.3
- /usr/bin/python3 --version : Python 3.4.3
- /usr/bin/python2 --version : Python 2.7.9

Please provide any additional information below.
Changing 'python' to 'python2' in generator/protoc-gen-nanopb solves the 
problem for me. For now, I have changed protoc-gen-nanopb as follows to get it 
work on any other system despite the python version:

MYPATH=$(dirname "$0")

python2="python"

if python -V 2>&1 | grep "Python 3." 1>/dev/null ; then
    python2="python2"
fi

exec ${python2} "$MYPATH/nanopb_generator.py" --protoc-plugin

But I am not sure, if any other distribution coming with python3 is offering 
python in version 2 as python2.

Original issue reported on code.google.com by firatkas...@gmail.com on 27 Apr 2015 at 9:50

GoogleCodeExporter commented 9 years ago
This issue was updated by revision 0dcfa096e69c.

Original comment by Petteri.Aimonen on 28 Apr 2015 at 3:15

GoogleCodeExporter commented 9 years ago
Thank you and very elegant solution! "which python2 || which python"

Original comment by firatkas...@gmail.com on 28 Apr 2015 at 3:41