executing python code

Ian Bicking ianb at colorstudy.com
Fri Nov 5 18:20:55 EST 2004


Darren Dale wrote:
> Some time ago I asked about executing a python program or script. For
> windows, I was informed that the .py extension could be added to some list
> of executable extensions, and then I could just type "mycode" instead of
> "python mycode.py". Great advice, worked like a charm.
> 
> I recently jumped ship, and have been running Gentoo Linux for about two
> months. Is it possible to get the same behavior on Linux? I thought it
> would have something to do with adding the #!/usr/bin/env python line to my
> code, but I'm not sure what this is supposed to do (it didnt work, that
> much I know.)

chmod +x mycode.py
./mycode.py

Note: . (the present directory) probably isn't in your $PATH, so you 
have to use ./ to tell the shell to look in the present directory.  Do 
"echo $PATH" to see where you can put it where it's always accessible. 
You also have to include the extension.  If you want, you can rename it 
to leave off the extension, and that will work fine.  You can also make 
a symlink, like (as root):

cd /usr/local/bin
ln -s /path/to/mycode.py mycode

~/bin is also often in the $PATH, instead of putting it in /usr/local/bin.

-- 
Ian Bicking  /  ianb at colorstudy.com  /  http://blog.ianbicking.org



More information about the Python-list mailing list