Search code examples
pythondjangopythonanywhere

Shebang for scripts not working


I am using PythonAnyhwere for my django production environment. I have a script which should run on scheduled basis.

Since I installed django in a virtualenv, the script starts like

#!/usr/bin/env python
activate_this = '/home/myname/.virtualenvs/myenv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

The error I get for this is

/usr/bin/env python: no such Python interpreter

No problem. So I changed it to

#!/usr/bin/env python2.7

Then I got

/usr/bin/env python2.7: no such Python interpreter

or

/usr/bin/env python3.4: no such Python interpreter

I said ok, what if I don't have a shebang line at all? Error in log:

line 1: activate_this: command not found
line 2: syntax error near unexpected token `activate_this,'
line 2: `execfile(activate_this, dict(__file__=activate_this))'

What is the way then?


Solution

  • You can know where your Python interpreter by typing

    $ which python
    

    Also you try something like this (or maybe without env):

    $ env python
    Python 3.5.0 (default, Sep 20 2015, 11:28:25) 
    [GCC 5.2.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> os.path
    <module 'posixpath' from '/usr/lib/python3.5/posixpath.py'>
    

    And then change lib to bin and omit /posixpath.py part