Q:

Scheduling django command within virtual env with cron

I'm trying to schedule the execution of a django command with cron, executed within a virtualenv.  I'm scheduling the execution of a script where I activate thye virtualenv and then execute the command. 
The problem is that when trying to activate the virtualenv it's raising the eror No such file or directory. 
/opt/django/myproj/myapp/cron/myscript.sh: line 2: /opt/virtualenvs/myvirtualenv
/bin/activate
: No such file or directory
Traceback (most recent call last):
  File "/opt/django/myproj/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 261, in fetch_command
    commands = get_commands()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 107, in get_commands
    apps = settings. INSTALLED_APPS
  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 54, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 49, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 132, in __init__
    % (self. SETTINGS_MODULE, e)
ImportError: Could not import settings 'myproj.settings

' (Is it on sys.path?  Is there an import error in the settings file?):  No module named settings

This is what I have:
CRON JOB:
* * * * * bash /opt/django/myproj/myapp/cron/myscript.sh > /opt/django/myproj/log/myscript.log 2>&1

MYSCRIPT.SH (simplified)
1 #! /bin/bash
2 source /opt/virtualenvs/myvirtualenv/bin/activate
3 python /opt/django/myproj/manage.py testcommand 

MYSCRIPT.SH (original script, same result anyway)
1 #! /bin/bash
2 SHELL=/bin/bash
3 DJANGO_SETTINGS_MODULE=myproj.settings
4 VIRTUALENV_DIR='/opt/virtualenvs/myvirtualenv'
5 export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
6 export PYTHONPATH=${VIRTUALENV_DIR}:${PYTHONPATH}
7 source ${VIRTUALENV_DIR}/bin/activate
8 python /opt/django/myproj/manage.py testcommand

Any help will be appreciated. 

A:

I solved it by removing the virtualenv activation from the script:
#! /bin/sh
/opt/virtualenvs/myvirtualenv/bin/python /opt/django/myproj/manage.py testcommand 

