30
# from lxml import etree; import module2dbk; print module2dbk.xsl_transform(etree.parse('test-ccap/col10614/index.cnxml'), []);

Error: bash: syntax error near unexpected token `('

4
  • 20
    The error message indicates that the script gets executed by bash, not python. Try adding #!/usr/bin/python as the first line of the file. Commented May 20, 2012 at 18:34
  • 4
    why is your first line commented out ? Commented May 20, 2012 at 18:35
  • Stack Overflow is a Q&A site, but there's no question here. However, the comments and answers seem useful, so maybe we could edit in a question. Judging by the accepted answer, you didn't understand what the error meant at all and didn't realize you were putting Python code into a Bash shell, so a good question could be, say, "Why am I getting an error from Bash when I'm trying to run Python code?" BTW, if you were starting with your own research, a good start could be "what is Bash?" Commented Sep 16, 2024 at 19:46
  • @zmo Judging by the error, it's not actually commented out; the hash # is actually the admin prompt (vs the non-admin prompt $). BTW there was a formatting error I just fixed; it was all supposed to be on one line. Commented Sep 16, 2024 at 19:50

4 Answers 4

73

add #!/usr/bin/env python at the top of your script, or call your script using python myscript.py

Sign up to request clarification or add additional context in comments.

Comments

25

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

Comments

16

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

Comments

0

I was having a similar problem with the same error, and the comment from tripleee helped me understand:

The error message indicates that the script gets executed by bash, not python.

Their solution of adding !/usr/bin/python at the very start of my code didn't do it for me, but I noticed that my code(extra).py contained parentheses (), so I renamed to my codeextra.py and that was it, problem solved. :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.