Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python raise - SyntaxError when running as an executable

Tags:

python

When I run my .py file from terminal I got no error, but when I run in as an executable (the exact same app) I get an error on this line

raise RuntimeError(f'Line lengths in the {file} are not ok. Please check it.')

When I comment it out it works. The error is: SyntaxError: invalid syntax pointing to the ' symbol at the end of the line. I do not understand how is it possible the file works without an error when running from terminal but not when run as executable.

like image 962
romanzdk Avatar asked Nov 15 '25 05:11

romanzdk


1 Answers

Ok I am sorry - my stupid bad. When I was running the file from "terminal" - IDE used python 3.7.4 but when I run it as an (macOS) executable the default python command was using python 2.7.

So I just changed first line of the app to:

#!/usr/bin/env python3

Or one may also change alias for python.

like image 60
romanzdk Avatar answered Nov 17 '25 19:11

romanzdk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!