LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-15-2005, 08:40 PM   #1
Chomper
LQ Newbie
 
Registered: Jan 2005
Location: Columbus Ohio
Distribution: Slackware 11
Posts: 23

Rep: Reputation: 15
Where is the Python Interpreter?


I'm trying to follow some easy tutorials for python and i can't seem to find the "python interpreter".

I'm using:
Python 2.3.4 (#1, Oct 26 2004, 16:42:40)
[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2

I made a file called "brian":
Code:
#!/usr/bin
print "hey there"
print 2*8
i gave it executable permission with chmod +x brian

when i try to run it i get this:
Code:
$ brian
bash: brian: command not found
i don't know how to get this thing to work. I assume my problem is that i'm not calling the python interpreter correctly. I don't know much about linux yet so i'm not yet sure what all the different types of files are. I've done a search for "python" on the computer and i get over 100 things and i'm not sure about what any of it is/does. Here are the other paths i've tried:

#!/usr/local/bin/python
#!/usr/bin
#!/usr/lib
#!/
#!/usr/local/bin
#!/usr/lib/python2.3
#!/usr/lib/ooo-1.1/program

all of these yield me the same error. Any help on this would be greatly appreciated. Thanks...
 
Old 01-15-2005, 08:42 PM   #2
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
try "#!/usr/bin/python"

if you want to run 'brian', you need to use "./brian" because it is not in your $PATH. Or you can use a full pathname ie "/home/brian/code/brian"

Last edited by bulliver; 01-15-2005 at 08:44 PM.
 
Old 01-15-2005, 08:46 PM   #3
Chomper
LQ Newbie
 
Registered: Jan 2005
Location: Columbus Ohio
Distribution: Slackware 11
Posts: 23

Original Poster
Rep: Reputation: 15
i still get the same error. am i trying to call the file wrong? the tutorial says i only have to type the filename to get it to execute.
 
Old 01-15-2005, 08:49 PM   #4
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
OK, run "which python", use the path it gives you with the "#!" added first.

Now where is this 'brian' you are trying to run? If it is not in your path then you need to use "./"
 
Old 01-15-2005, 08:58 PM   #5
Chomper
LQ Newbie
 
Registered: Jan 2005
Location: Columbus Ohio
Distribution: Slackware 11
Posts: 23

Original Poster
Rep: Reputation: 15
Alright i'm confused....

Code:
$ which python
/usr/bin/python
which is what i'm already using

'brian' is saved in /home/chomper and that's where i am at when i try to run 'brian' . i tried ./brian and it worked. i don't understand that. how am i not in the directory where it's saved when i obviously am? what's my problem?

i made another brian in another directory and it's the same thing. it doesn't work without the ./ first. please explain...
 
Old 01-15-2005, 09:20 PM   #6
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
Ok, unless a script or program is in your $PATH variable, you need to call the program explicitly. $PATH is just a list of directories that bash looks for programs in. Your home directory is typically not in the PATH, so you need to tell bash where the script is using either:
Code:
$ /home/chomper/brian  
# or, if you are in /home/chomper...
$ ./brian
"./brian" tells bash to look in the present directory, as "." is shorthand for the current directory.
 
Old 01-15-2005, 09:33 PM   #7
Chomper
LQ Newbie
 
Registered: Jan 2005
Location: Columbus Ohio
Distribution: Slackware 11
Posts: 23

Original Poster
Rep: Reputation: 15
Ah-ha...i see. Well thanks a bunch helping me jump my first python hurdle and teaching me some too.

Out of curiosity, how would i alter this $PATH thing you speak of so i could point it to a directory containing commands i want bash to recognize? This will be for my future reference, once i code something cool.

Thanks again!
 
Old 01-15-2005, 09:41 PM   #8
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
Quote:
Out of curiosity, how would i alter this $PATH thing you speak of so i could point it to a directory containing commands i want bash to recognize? This will be for my future reference, once i code something cool.
Code:
$ export PATH=$PATH:/some/new/directory
Basically all this does is tack "/some/new/directory" on the end of your current PATH. Keep in mind that this will only take effect for the current terminal session. If you want to permanent you need to stick it in either ~/.bashrc or ~/.bash_profile.
 
Old 01-15-2005, 09:56 PM   #9
Chomper
LQ Newbie
 
Registered: Jan 2005
Location: Columbus Ohio
Distribution: Slackware 11
Posts: 23

Original Poster
Rep: Reputation: 15
cool. Thanks alot!
 
  


Reply



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
Processing Conflict: python-devel conflicts python< 2.3.4-13.1 guarriman Fedora 2 04-23-2009 07:02 PM
installing python library's (Python Numeric) Four Linux - Newbie 1 10-16-2005 02:31 PM
WineX, python-gnome, and python-gtk DrD Fedora 0 08-03-2004 12:11 PM
install python 2.3 ,necssary to remove python 2.2 ngan_yine Linux - Newbie 7 12-28-2003 04:07 PM
Does Python interpreter have weird delay? lugoteehalt Programming 4 11-12-2003 01:43 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:32 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration