bash: syntax error near unexpected token `(' - Python

前端 未结 4 1559
野的像风
野的像风 2020-12-03 10:37
# from lxml import etree; 
import module2dbk; 
print module2dbk.xsl_transform(etree.parse(\'test-ccap/col10614/index.cnxml\'), []);

Error: bash: syntax error near u         


        
相关标签:
4条回答
  • 2020-12-03 10:50

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

    0 讨论(0)
  • 2020-12-03 11:08

    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

    0 讨论(0)
  • 2020-12-03 11:09

    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. :)

    0 讨论(0)
  • 2020-12-03 11:13

    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
    
    0 讨论(0)
提交回复
热议问题