title: How to set environment variables in virtualenv
body: <p>If I have python script which activates the virtualenv like this:</p>
  
  <pre><code>#!/path/to/venv/bin/python
  </code></pre>
  
  <p>How can I set variables for this script without modifying this script?</p>
  
  <p>I want this environment variable to be active for <strong>all</strong> scripts which use this virtualenv.</p>
  
  <p>This means modifying this script is not a solution, since there are twenty scripts, and I don't want to modify twenty scripts.</p>
  
  <p>Writing a shell wrapper-script around the python scripts would work, but I would like to avoid this.</p>
  
  <p>In the past I thought a custom <code>sitecustomize.py</code> can be used for start-up code. But Ubuntu (AFAIK the only distribution which does this) comes with its own sitecustomize.py file, with the effect that my sitecustomize.py does not get called. See <a href="https://bugs.launchpad.net/ubuntu/+source/python2.5/+bug/197219" rel="noreferrer">https://bugs.launchpad.net/ubuntu/+source/python2.5/+bug/197219</a></p>
  
  <p>Here are some ways how I want to use the virtualenv:</p>
  
  <ul>
  <li>Script which gets executed via unix cron.</li>
  <li>virtualenv in a systemd service. See: <a href="https://stackoverflow.com/questions/37211115/how-to-enable-a-virtualenv-in-a-systemd-service-unit">How to enable a virtualenv in a systemd service unit?</a></li>
  <li>via mod_wsgi (Apache): <a href="https://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html#daemon-mode-single-application" rel="noreferrer">https://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html#daemon-mode-single-application</a></li>
  </ul>
  
  <p>(I have thought about this again. I guess it setting the variables is not the job of python or virtualenv. I need a unified way to set environment variables. And in my case I would like to do this without using a shell wrapper).</p>