LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Where is the Python Interpreter? (https://www.linuxquestions.org/questions/programming-9/where-is-the-python-interpreter-278258/)

Chomper 01-15-2005 08:40 PM

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

bulliver 01-15-2005 08:42 PM

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"

Chomper 01-15-2005 08:46 PM

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.

bulliver 01-15-2005 08:49 PM

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 "./"

Chomper 01-15-2005 08:58 PM

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

bulliver 01-15-2005 09:20 PM

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.

Chomper 01-15-2005 09:33 PM

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!

bulliver 01-15-2005 09:41 PM

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.

Chomper 01-15-2005 09:56 PM

cool. Thanks alot!


All times are GMT -5. The time now is 06:21 AM.