Forums

How to override hashbang...

I have a script with a hashbang to a particular Python interpreter that works great, however if I want to have the script run with a different Python interpreter on the scheduler tab, I have an issue. I tried creating a task with the command of: /usr/local/bin/python3.2 /home/a2j/path/to/script.py "sys.argv stuff here", however this does not override the hashbang. Please help...thx.

Hi a2j -- that's odd, if you specify the Python interpreter when you set up the scheduled task, it certainly should use that one. I'll take a look.

Hmm, OK. I can't reproduce this. I created a file called /home/giles/p27hashbang.py with the following contents:

#!/usr/local/bin/python2.7

import sys
print(sys.version)

I made it executable and confirmed that the hashbang worked from a bash console:

14:56 ~ $ chmod +x p27hashbang.py                                                                                                                           
14:57 ~ $ ./p27hashbang.py                                                                                                                                  
2.7.3 (default, Jun  7 2012, 18:18:02) 
[GCC 4.4.5]
14:57 ~ $

Then I confirmed that if I specified the Python version on the command line, it used the specified version:

14:57 ~ $ /usr/local/bin/python3.2 p27hashbang.py                                                                                                           
3.2.3 (default, Jun  7 2012, 18:25:14) 
[GCC 4.4.5]
14:57 ~ $

Then I created a scheduled task that ran it, also specifying the Python version:

/usr/local/bin/python3.2 /home/giles/p27hashbang.py

The log output from this was:

3.2.3 (default, Jun  7 2012, 18:25:14) 
[GCC 4.4.5]

2012-06-22 14:59:10 -- Completed task, took 2.00 seconds, return code was 0.

Would you like me to take a look at your scheduled tasks and see if there's a difference? We can switch to email if there's private stuff involved.

Here are my results:

#!/usr/local/bin/python3.2

import sys, os

print(sys.executable, os.sys.executable)
print(sys.argv)

Running this file from the schedule tab as command:

/path/to/file.py some parameters here

returns a log entry of:

/usr/local/bin/python3.2 /usr/local/bin/python3.2
['path/to/file.py', 'some', 'parameters', 'here']

2012-06-22 17:29:06 -- Completed task, took 1.00 seconds, return code was 0.

Running the file from the schedule tab as command:

/usr/local/bin/ipython3.2 /path/to/file.py some parameters here

returns a log entry of:

/usr/local/bin/python3.2 /usr/local/bin/python3.2
['/path/to/file.py', 'some', 'parameters', 'here']

2012-06-22 17:57:08 -- Completed task, took 3.00 seconds, return code was 0.

Notice the return of sys.executable and os.sys.executable in both are with out the i from iPython.

iPython is a Python app that runs on an underlying Python executable, so the executable will always be reported as python and not ipython.

duh...Can we call it a blonde moment and forget I had that issue?

Heh. What issue, I didn't see an issue. Maybe it went that way.