Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble activating virtualenv on server via Fabric
    text
    copied!<p>I am trying to run some Django management commands via Fabric on my staging server. </p> <p>The problem is it seems Fabric is not able to activate the virtualenv and thus using system python/libs when executing the commands. </p> <p>On the server the Django app is run using a virtualenv (no, I don' use virtualenvwrapper yet...)</p> <p>Using Fabric (1.0.1) a command might look like this when run from my box:</p> <p><strong>The fabfile method:</strong></p> <pre><code>def collectstatic(): require('settings', provided_by=[production, staging]) with settings(warn_only=True): run('source %(env_path)s/bin/activate &amp;&amp; python %(repo_path)s/%(project_name)s/configs/%(settings)s/manage.py collectstatic --noinput -v0' % env) </code></pre> <p><strong>The output:</strong></p> <pre><code>$ fab staging master collectstatic [myserver.no] Executing task 'master' [myserver.no] Executing task 'collectstatic' [myserver.no] run: source /home/newsapps/sites/mysite/env/bin/activate &amp;&amp; python /home/newsapps/sites/mysite/repository/mysite/configs/staging/manage.py collectstatic --noinput -v0 [myserver.no] Login password: [myserver.no] out: Unknown command: 'collectstatic' [myserver.no] out: Type 'manage.py help' for usage. </code></pre> <p>I know of course that the Django command collectstatic does not exist in versions prior to 1.3 which leads med to think that system python (which has Django 1.2) is beeing used. </p> <p>My fabfile/project layout is based on the <a href="https://github.com/newsapps/hello_newsroom/blob/master/fabfile.py" rel="noreferrer">great fabfile of the Tribapps guys</a></p> <p>So I created a fabric method to test pythonversion:</p> <pre><code>def pythonver(): require('settings', provided_by=[production, staging]) with settings(warn_only=True): run('source %(env_path)s/bin/activate &amp;&amp; echo "import sys; print sys.path" | python ' % env) </code></pre> <p>When run it gives the following output: </p> <pre><code>$ fab staging master pythonver [myserver.no] Executing task 'master' [myserver.no] Executing task 'pythonver' [myserver.no] run: source /home/newsapps/sites/mysite/env/bin/activate &amp;&amp; echo "import sys; print sys.path" | python [myserver.no] Login password: [myserver.no] out: ['', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/usr/lib/pymodules/python2.6', '/usr/lib/pymodules/python2.6/gtk-2.0', </code></pre> <p>As you can see it uses system python and not my virtualenv located in home/newsapps/sites/mysite/env</p> <p>But if I run this command directly on the server</p> <pre><code>source /home/newsapps/sites/mysite/env/bin/activate &amp;&amp; echo "import sys; print sys.path" | python </code></pre> <p>.. then it outputs the right paths from the virtualenv</p> <p>What am I doing wrong since the commands are not run with the python from my virtualenv using Fabric?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload