Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss] Python script question



On 08/03/2011 10:44 AM, Dan Ritter wrote:
> On Wed, Aug 03, 2011 at 10:28:20AM -0400, Jerry Feldman wrote:
>> A coworker of mine has a Python script set up as:
>> #! $PATH_TO_PYTHON/python
>> ... python code
>>
>> It is not unusual to have commands like this. Mailman does this with
>> several of its commands. The issue here is that he needs to use an
>> environment variable to call the python interpreter. We certainly can do
>> it a messy way:
>> #! /bin/bash
>> $PATH_TO_PYTHON/python foo.py
>>
>> But this would require a wrapper script.
>>
>> Or he can use an explicit path to the python interpreter.
>> #! /usr/bin/python
>>
>> The problem here is that the version of python he uses MUST be
>> encapsulated in our company's product.
>> #! /mnt/fubar/versionxyz/bin/python
>>
>> But this will possibly differ with each release of our company's product
>> since we maintain a number of releases here.  Some other solutions is to
>> set up symlinks in the local directory. 
>>
>> Any ideas on how to get the loader to expand the environment variable
>> after the #!??
> You can't do that, because it's parsed by the kernel, not the
> shell.
>
> Here's my suggestion:
>
> create /mnt/fubar/product-current as a link to
> /mnt/fubar/versionxyz/
>
> and maintain that.
>
> Now your script can start:
>
> #!/mnt/fubar/product-current/bin/python
>
> Alternatively, install your python script in
> /mnt/fubar/versionxyz/scripts/
>
> and start with:
>
> #!../bin/python
>
> (I just tested that, and it works.)
>
> -dsr-
>
Yes. We do that with our products. The issue here is that his scripts
may have to work with different versions, not only the current, but he
could have a wrapper script to set a symlink.


-- 
Jerry Feldman <gaf at blu.org>
Boston Linux and Unix
PGP key id: 537C5846
PGP Key fingerprint: 3D1B 8377 A3C0 A5F2 ECBB  CA3B 4607 4319 537C 5846





BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org