[Tutor] Linux Programs

Bruce Sass bsass@freenet.edmonton.ab.ca
Thu, 3 May 2001 23:42:33 -0600 (MDT)


On Thu, 3 May 2001, Timothy M. Brauch wrote:

> Rick Pasotto wrote:
> >
> > I think the prefered way is:
> >
> > #!/usr/bin/env python
> >
> > This should find the appropriate python no matter where it's located.

Ya.  /usr/bin/env should exist on every(?) unix-like system, it will
find the interpreter, which could be in /usr/bin, /usr/local/bin,
etc.

I recommend using: "#!/usr/bin/env pythonX.Y", if the script will only
work with python version X.Y - you may only have one version of python
installed, I have three.

> > > This line doesn't work on my computer.  All I get is the file openned in
> > > a text editor.
> >
> > Huh? This doesn't make sense to me. In unix you don't get an editor
> > unless you *ask* for an editor.
> >
> > How are you trying to run the file?  What is your command line? Or are
> > you in X and clicking on an icon?
> >
> > Even without the '#!' line and regardless of the permissions (well, you
> > do need 'read' permission) you can run your program by entering:
> >
> > python test.py
>
> Yeah, I realized that right after I sent this, I probably wouldn't be
> able to just click on an icon in X, like I was used to in Windows.  But,

That will depend on which window manager/desktop you are using.
I'm using KDE and can get an icon to do pretty much anything when
clicked on (expect to fiddle a bit, downside of not having a central
controling authority that dictates what is "right").

> I am also having problems using command line.  Still, I can run the
> program using 'python test.py' if I am in the folder 'test.py' is
> stored.  I am still wondering if it is possible to just type 'test.py'

A period (".") is defined as the current working directory.  So you
can do "./test.py" to run something in the dir you are in (resist the
temptation to add "." to your PATH).  Otherwise you use the full path,
or put (or symlink) the programs in a dir on your path (/usr/local/bin
is a good choice, and adding a bin dir to your home dir is fairly
common).

> (as long as I am in the folder, or preferrably, anywhere).  I tried
> using 'export PATH=$PATH: /home/tbrauch/python_files' but I get the
> following error message
>
> bash: export: `/home/tbrauch/python_files': not a valid identifier

try: "export PATH=$PATH:/home/tbrauch/bin"
instead (or python_files, whatever turns your crank).
i.e., drop the space and the single quotes, bash sees the /home/...
bit as an environment var to be exported.

> I'm not trying to turn this into a Linux tutorial, I just hope to get
> Python working on my new computer...

<shrug> :)


- Bruce