[Pythonmac-SIG] Running Python scripts without full paths

Paul Berkowitz berkowit@silcom.com
Sat, 30 Nov 2002 10:56:34 -0800


It works for me now! First of all, thank you for

setenv PATH "~/bin:/Users/kevin:${PATH}"

syntax. (I didn't trust the ~ to resolve within quotes so I spelled it out.=
)

What you're missing is the .MacOSX folder and the XML file you have you mak=
e
there. That's how it's done in OS X, it seems, not with .tcshrc or init
files. See=20


    http://www.astro.washington.edu/owen/AquaEnvVar.html


That's how to do it. I had already used it to import modules within the
Interactive interpreter. Now that I've got the shebang and PATH variable
correct, it also works to run .py files from the Terminal.

That's the solution. Russell says he got it from the people at BBEdit.
Obviously, Apple needs to document it somewhere. I believe it will soon be
added to the FAQ at python.org: I had some correspondence on this last
night.


--=20
Paul Berkowitz



> From: kevin parks <kevin@macosx.com>
> Date: Sun, 1 Dec 2002 03:33:44 +0900
> To: pythonmac-sig@python.org
> Subject: Re: [Pythonmac-SIG] Running Python scripts without full paths
>=20
> For what it is worth i have never ever ever found a solution to this
> problem My path is set in the
>=20
> ~/Library/init/tcsh/environment.mine
>=20
> by adding:
> setenv PATH "~/bin:/Users/kevin:${PATH}"
>=20
> since path is an environmental variable i am not sure why there is a
> path file (and why it is not called path.mine) and a separate
> environment.mine file.
>=20
> Should i have set this in:
>=20
> ~/Library/init/tcsh/path    ??? and if so how? it is a mystery and
> Apple is not going to tell you either.
>=20
> I also have the sbang set all fine and the file set to executable and
> no go. I have asked this on the list over and over and many fine folks
> have tried to help me but to no avail. If i execute the script with the
> full path it is fine if i just move to the directory (which *IS* in my
> path), make a script and then try to execute it i get "command not
> found". I checked my sanity and did the same thing on a linux box and
> everything works, so i have no clue. The weirdest thing of all is if
> you hop into the terminal and print your path from the command line it
> show that the dir is listed in the path after all.
>=20
> Intensely frustrating. I have no idea why this is.
>=20
> I have just bit the bullet and type the whole freaking path for now. I
> hate this part of Mach-o python and really dislike how Apple keeps
> changing the unixy things with the terminal and not giving anything but
> the most terse instructions on how to customize tcsh. It changed from
> 10.1 to 10.2. The system they have is very nice and BSD-y but it takes
> days of investigation to get your stupid ~/Library/init/tcsh/ files
> working. Once you figure out what the are and what they do. I suspect
> that most folks have ignored the BSD way and just put a .tcshrc file in
> their home directory which overrides.
>=20
> If i am right what the OS X ~/Library/init/tcsh/ system tries to do is
> have a system wide set-up with the shell which you then amend with your
> own ~/Library/init/tcsh files, but if you just put a .tcshrc file in
> your home the system wide startup log-in log-out aliases and path files
> get clobbered, no? Who knows? Someone at Apple ought to make this clear
> instead of just that dumb single cryptic file that the give you in
>=20
> /usr/share/tcsh/examples/README
>=20
> You know the files they moved from /usr/share/init/tcsh without telling
> anyone making sure that anyone who used the terminal had a few days of
> frustration after moving to Jaguar.
>=20
> Frankly i still can't figure out for sure what is going on with tcsh on
> OS X. On the NeXT is was simple you had your
> .tcshrc .login and .logout files in your home and that was it. Plus
> they were documented.  I am still not sure what is supposed to go in the
>=20
> aliases.mine        - shell aliases
> completions.mine    - completions
> environment.mine    - environment
> rc.mine            - run commands
> path            - command search path
>=20
> files exactly. I realize that this is just .tcshrc broken up into
> separate files, but what is rc.mine (is that supposed to be a
> substitute for the .cshrc file?) and why is path not path.mine? and as
> i stated above since path is an environmental variable i am not sure
> why there is a path file and a separate environment.mine file. The
> whole thing is a mess and not at all documented. REAL examples would
> have been nice. I am not sure who Fred Massachusetts Institute of
> Technology  tritan@mit.edu is but i sure wish he would have written a
> less terse readme.
>=20
>=20
> I realize that i am a freak in that 1) i want actually write scripts to
> execute from the shell (heaven forbid!)
> 2) i like the terminal and actually want to use it.
>=20
> But Apple hates users like me apparently since the do all they can to
> make sure you don't use the shell, including moving stuff around and
> not giving you any documentation on how to set up your shell. The csh
> books out there are not any use either since they have nothing on the
> new BSD ways. I hate this! I would love to know once and for all how to
> set up my shell so that i can add directories to my path like ~/bin
> and type
>=20
> % foo.py
>=20
> and get a result. But i guess that is just never going to happen.
>=20
>=20
>=20
>=20
>> Thanks, Neil. That's the odd thing. I did all that (sorry I forgot to
>> mention it), except I left a space between after the #! , before
>> 'usr/bin/env python'. I've now tried it all ways:
>>=20
>> =A0=A0=A0=A0#!/usr/bin/python
>> =A0=A0=A0=A0#!/ usr/bin/python
>> =A0=A0=A0=A0#!/usr/bin/env python
>> =A0=A0=A0=A0#!/ usr/bin/env python
>>=20
>> Even when I give the full path to the file:
>>=20
>> [250-166:~] berkowit% ~/Library/Scripts/Python/module1.py
>> /Users/berkowit/Library/Scripts/Python/module1.py: Command not found.
>>=20
>>=20
>>=20
>> I get "Command not found."every time. =A0What am I doing wrong?
>>=20
>> Here are the permissions:
>>=20
>> -rwxr-xr-x =A01 berkowit =A0wheel =A0=A0=A048 Nov 30 08:47 module1.py
>>=20
>> Here's the current version of the file (with Unix newlines):
>>=20
>> #!usr/bin/python
>> print 'Hello module world!
>=20
>=20
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig
>=20