Rose Rose - 5 months ago 62
Linux Question

syntax error near unexpected token while executing a python file

I was trying to execute a python file which 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

Answer

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