Wednesday, December 29, 2021

[SOLVED] syntax error near unexpected token while executing a python file

Issue

I was trying to execute a python file which is not saved in the python directory but in a different one in linux (fedora) terminal. What I tried was:

$ exec(vsh1.py)

which resulted an error:

bash: syntax error near unexpected token 'vsh1.py'

Could anybody find a solution please... Thanks in advance


Solution

Locate your python's source file

find / -name vsh1.py

and once located run

 python /path_you_found/vsh1.py

if you want your script to be seen from any location for the interpreter you have to add it to PYTHONPATH:

 PYTHONPATH=$PYTHONPATH:/path_you_found/vsh1.py

if your script in the same directory you can just run

python ./vsh1.py  


Answered By - dmitryro