By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,986 Members | 1,568 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,986 IT Pros & Developers. It's quick & easy.

How to run a Python script.

P: 2
I am running Mac OS 10.6.4...I know this is embarrassingly simple, but I've spent hours on this. I'm beginning to think there might be an installation problem with Python. I stupidly removed MacPython from my Applications file, then when I realized what I had done, downloaded and installed Python2.6.6
Using IDLE, I created File attached.
In a terminal window, after chmod +x and then ./, I get this error: syntax error near unexpected token `('
Here is the complete contents of the terminal window:

Last login: Tue Sep 21 12:49:02 on ttys000
mjmmacbook:~ michaelmullin$ chmod +x
mjmmacbook:~ michaelmullin$ ./
./ line 1: syntax error near unexpected token `('
./ line 1: `Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51) '
mjmmacbook:~ michaelmullin$

I get the same error even when the .py file contains a real script (downloaded from web and tested by many)
Including #!/usr/bin/env python2.6.6 (or just ...python) does not change the error.

I've been thinking about reloading my operating system, but not sure that will help and its a little radical.

I hope someone can get me on track.
Many Thanks,
Attached Files
File Type: txt test.txt (592 Bytes, 266 views)
Sep 21 '10 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 621
./ line 1: syntax error near unexpected token `('
./ line 1: `Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51) '
You have
(Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51)
on the first line of the program, which the interpreter doesn't like. Usually that happens when you think you are running one program, but are actually running another program, perhaps in another directory.
Sep 22 '10 #2

P: 2
Thanks dwbias, I see what you are saying.
I now realize I can run the script without all of the header info, e.g.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/env python
  3. from mapnik import *
  5. mapfile = 'world_styles.xml'
  6. map_output = 'hello_world_using_xml_config.jpg'
  7. projection = '+proj=latlong +datum=WGS84'
  9. m = Map(600,400)
  10. load_map(m, mapfile)
  11. bbox = Envelope(Coord(-180, 90), Coord(180.0, -90))
  12. m.zoom_to_box(bbox)
  13. render_to_file(m, map_output)
This is similar to the code I was trying to run in the first place.
Sep 22 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.