bash: syntax error near unexpected token `(' – Python
Question:
# from lxml import etree;
import module2dbk;
print module2dbk.xsl_transform(etree.parse('test-ccap/col10614/index.cnxml'), []);
Error: bash: syntax error near unexpected token `('
Answers:
add #!/usr/bin/env python
at the top of your script, or call your script using python myscript.py
Are you typing this at the unix command prompt? You should be doing this inside the python environment, ie. type python
at the prompt and work from there.
Also, no ;
needed at the end of the line in Python
add
#!/usr/bin/env python
or but i will prefer to use the above one.
#!/usr/bin/python
In case you have installed python 2 and python 3 and python 2 is default you can run python 3 by using these command
#!/usr/bin/env python3
at top of the file
or run this way
python code.py
Well I had exactly the same problem. I had tried everything and nothing really worked. My program was running perfectly on Windows command prompt, and on my iPhone Python app interpreter, but not on my Macbook’s terminal, where I always got the following error whenever I tried to run the program:
bash: syntax error near unexpected token `(‘
Finally the comment above from the user tripleee helped me come up with a solution; although his solution of adding !/usr/bin/python
at the very start of my code didn’t do it for me it helped me understand as he wrote that:
The error message indicates that the script gets executed by bash, not python.
Then I noticed that my code(extra).py contained ‘(‘ apostrophes, I renamed to my codeextra.py and that was it, problem solved. 🙂
# from lxml import etree;
import module2dbk;
print module2dbk.xsl_transform(etree.parse('test-ccap/col10614/index.cnxml'), []);
Error: bash: syntax error near unexpected token `('
add #!/usr/bin/env python
at the top of your script, or call your script using python myscript.py
Are you typing this at the unix command prompt? You should be doing this inside the python environment, ie. type python
at the prompt and work from there.
Also, no ;
needed at the end of the line in Python
add
#!/usr/bin/env python
or but i will prefer to use the above one.
#!/usr/bin/python
In case you have installed python 2 and python 3 and python 2 is default you can run python 3 by using these command
#!/usr/bin/env python3
at top of the file
or run this way
python code.py
Well I had exactly the same problem. I had tried everything and nothing really worked. My program was running perfectly on Windows command prompt, and on my iPhone Python app interpreter, but not on my Macbook’s terminal, where I always got the following error whenever I tried to run the program:
bash: syntax error near unexpected token `(‘
Finally the comment above from the user tripleee helped me come up with a solution; although his solution of adding !/usr/bin/python
at the very start of my code didn’t do it for me it helped me understand as he wrote that:
The error message indicates that the script gets executed by bash, not python.
Then I noticed that my code(extra).py contained ‘(‘ apostrophes, I renamed to my codeextra.py and that was it, problem solved. 🙂