Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9189905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:20:24+00:00 2026-06-17T20:20:24+00:00

I have a number of scripts which need to specify the python binary which

  • 0

I have a number of scripts which need to specify the python binary which runs them:

#! /home/nargle/python/bin/python2.6

I need to adapt these scripts to work at two different sites. Lots of tools are installed in different places, so at new site 2 the script needs to start with:

#! /user/nargle/python/bin/python2.6
..

I want to replace directly-quoted paths with environment variables which are set differently for each site. What I would like is for this to work:

#! $MY_PYTHON_PATH

but it doesn’t! I am slightly hazy on where to research this. Is it the executing shell (be it bash, csh or whatever) which detects the ‘#!’ at the start of a script (be it bash, python or whatever) and fires up the interpreter/shell to run it?

I feel that there must be some way to do this. Please advise!

Oh yes, there is one more constraint: we cannot use the path for this. This may seem like a stupid restriction but this is for a large environment with many users

The environment is RHEL 5.7.

EDIT It has been suggested to use a shell script and that is the current plan: it works fine:

 $MY_PYTHON_PATH some_script file.py $@

The problem is really that we have lots of people using the python files, and lots of automated tests which need to changed. If it has to be done it has to be done but I if possible I want to minimise the impact of a change of working practice for scores of people.

EDIT It would also be possible to have a link in a location which is the same on both systems, and which links to the real binary in a different target on each system. This is quite feasible but seems kind of messy: we use the linux ‘modules’ package to setup environment variables for many tools and it would be nice if we could take the python path from our modulefiles.

EDIT It isn’t the answer but this feels like the kind of evil hack I was looking for:
http://docs.nscl.msu.edu/daq/bluebook/html/x3237.html
.. see “Example 4-2. #! lines for bash and for tclsh”

EDIT I hoped this might work but it didn’t:

!# /usr/bin/env PATH=$PATH:$MY_PYTHON_PATH python2.6
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:20:25+00:00Added an answer on June 17, 2026 at 8:20 pm

    We can do:

    #!/bin/bash
    "exec" "python" "$0"
    
    print "Hello World"
    

    from http://rosettacode.org/wiki/Multiline_shebang#Python

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have python script which downloads N number of images from website. I run
I have a number of scripts used to build a database. These need to
I currently have a number of Python scripts that help prep a staging area
I have a number of Python scripts I wrote a while back, to do
I have written a bash script which installs a number of packages, however for
I have a very large script which is creating multiple views. In a number
A little background: I have a perl script which is performing a number of
I have a number of tracking scripts and web services installed on my website
I have a number of manually written scripts (.sql) for tables, views and stored
On a website I have a number of small PHP scripts to automate changes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.