Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


  Search this Thread
Old 01-05-2011, 10:20 PM   #1
Registered: Oct 2010
Posts: 40

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

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)
 gregory@gregory-laptop:~/webdev-pp$ cd python-pp5
gregory@gregory-laptop:~/webdev-pp/python-pp5$ ls
gregory@gregory-laptop:~/webdev-pp/python-pp5$ python
  File "", line 5
    5   import pygtk
SyntaxError: invalid syntax
the script is from a tutorial I am following
this is the script
1   #!/usr/bin/env python
3   # example
5   import pygtk
6   pygtk.require('2.0')
7   import gtk
9   class Base:
10       def __init__(self):
11           self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
14       def main(self):
15           gtk.main()
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
Registered: Dec 2005
Location: Sheffield, UK
Distribution: Gentoo
Posts: 142

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
Registered: Oct 2010
Posts: 40

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
Registered: Dec 2005
Location: Sheffield, UK
Distribution: Gentoo
Posts: 142

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
Senior Member
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

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


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 > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:09 AM.

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