user2194805
user2194805

Reputation: 1369

Different shebang line for a python script depending on the system

I've a python script using the Django framework running from a virtualenv, and I'd like to use the same script on a different machine where the virtualenv is located in a different place.

The script is like this:

#!/home/lenovo/.virtualenvs/gjt/bin/python
sys.path.append('/home/lenovo/prj/gjt/gjt')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gjt.settings')
import django
django.setup()

To use the same script on a different machine, I'd need to change the shebangline to something else.

  1. Either can I define the shebang line based on the /etc/hostname file
  2. or somehow use #!/usr/bin/python as the shebang, and still be able to use the virtualenv from the mentioned location? Of course i need to change the sys.path.append accordingly, but that's not an issue.

Thanks.

Upvotes: 0

Views: 156

Answers (1)

Philippe
Philippe

Reputation: 26462

This shebang should be suitable for different vitual environments :

#!/usr/bin/env python

Upvotes: 2

Related Questions