LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 01-05-2011, 10:20 PM   #1
cre84j
Member
 
Registered: Oct 2010
Posts: 35

Rep: Reputation: 3
Python Installed; bash command: python base.py. gets syntax error in base.py


Python is installed
Apparently it's pyGTK2 ( it's 2.6.5 according to Synaptic Package Manager.

this is what shows on the bash terminal (trying to keep the
main directory uncluttered hence the webdev-pp directoy; it's my
main workspace)
Code:
 gregory@gregory-laptop:~/webdev-pp$ cd python-pp5
gregory@gregory-laptop:~/webdev-pp/python-pp5$ ls
base.py  pygtkconsole.py
gregory@gregory-laptop:~/webdev-pp/python-pp5$ python base.py
  File "base.py", line 5
    5   import pygtk
             ^
SyntaxError: invalid syntax
gregory@gregory-laptop:~/webdev-pp/python-pp5$
the base.py script is from a tutorial I am following
this is the script
Code:
1   #!/usr/bin/env python
2
3   # example base.py
4
5   import pygtk
6   pygtk.require('2.0')
7   import gtk
8
9   class Base:
10       def __init__(self):
11           self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
12           self.window.show()
13
14       def main(self):
15           gtk.main()
16
17   print __name__
18   if __name__ == "__main__":
19       base = Base()
20       base.main()
It seems obvious that python is not in the directory path or something like that. I have done the same sort of thing with ruby
and it works fine but think it must be something to do with the installation and if it is a systems wide installation or not
but am not sure what to try next.

Thank you in advance for any input you care to give. I am very new
to Linux and computer languages since late last year though some experience with PHP and MySQL from earlier last year and some Javascript during Multimedia studies while getting my Graphic design diploma. Its very new to me and just back from a long break on Holiday but what I have learned is coming back to me. I would appreciate your help very much.
 
Old 01-06-2011, 03:41 AM   #2
pgpython
Member
 
Registered: Dec 2005
Location: Sheffield, UK
Distribution: Gentoo
Posts: 141

Rep: Reputation: 32
The problem is with the line numbers in the file. You need to get rid of them and then it will work
 
Old 01-07-2011, 02:18 AM   #3
cre84j
Member
 
Registered: Oct 2010
Posts: 35

Original Poster
Rep: Reputation: 3
thanks I had to take the indents of of the lines as well and now it works

I do appreciate that python seems to need all the spacings to be right before it will
interpret the script so that seems to be a big part of the language.

thanks pgpython
 
Old 01-07-2011, 03:47 AM   #4
pgpython
Member
 
Registered: Dec 2005
Location: Sheffield, UK
Distribution: Gentoo
Posts: 141

Rep: Reputation: 32
That is correct, indentation is how python delimits blocks instead of braces. I don't mind this to be honest as good code should have good indentation anyway. The only thing you have to be careful of is if you mix tabs and spaces. The way to avoid this common problem is to set your editor up correctly. use a standard of 4 spaces of tabs and you should be fine
 
Old 01-23-2011, 04:46 PM   #5
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 230Reputation: 230Reputation: 230
cre84j, Solved? Please mark it so. TIA.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Python n00b: promoting a derived class to base class? CoderMan Programming 2 03-11-2010 01:46 PM
Python-Base 10 error (newbie) bandana_pig Programming 1 11-07-2008 04:38 PM
my apt-get does not work :(: "dpkg: error processing python-kaa-base (--configure):" frenchn00b Debian 3 04-22-2008 03:30 PM
bash syntax when envoking tar command in python script tangle Programming 4 02-04-2006 03:22 PM
no python module base.g? hcgernhardt Linux - Software 0 01-15-2005 12:16 PM


All times are GMT -5. The time now is 02:04 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration