title: Python Popen doesn't recognize scrapy when python script is run as systemd service
body: <p>I have a python script <code>main.py</code> that needs to start the <a href="https://scrapy.org/" rel="nofollow noreferrer">scrapy</a> executable, so I use Popen to do that (using <code>subprocess.call()</code> has same result). To simplify things I just run the help argument of scrapy.</p>
  
  <pre><code>import subprocess
  ...
  p = subprocess.Popen(['scrapy', '-h'])
  </code></pre>
  
  <p>The script needs to be run inside a vitualenv which has scrapy installed on it. When I activate the virtualenv and run the script as <code>python main.py</code> the command <code>scrapy -h</code> is executed as expected.</p>
  
  <p>Now, I need this script to be run as a systemd service. I have created the systemd unit for the script as follows:</p>
  
  <pre><code>[Unit]
  Description=Scrapy test
  After=network.target
  
  [Service]
  User={{ scrapy_user }}
  WorkingDirectory={{ test_path }}
  ExecStart={{ virtualenv_path }}/bin/python {{ test_path }}/main.py
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p>When I enable and start the service with <code>sudo systemctl start scrapy-test</code> the code runs normally until <code>p = subprocess.Popen(['scrapy', '-h'])</code> when I get an exception raised</p>
  
  <pre><code>File "{{ test_path }}/main.py", line 52, in launch_spider
     p = subprocess.Popen(['scrapy', '-h'])
  File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
     errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
     raise child_exception
  OSError: [Errno 2] No such file or directory
  </code></pre>
  
  <p>I have also tried to change the working directory by adding <code>os.chdir('{{ virtualenv_path }}/bin')</code> just before <code>Popen</code>, but I get the exact same exception. I am sure the script is run through the virtualenv because (1) it is set so in the <code>ExecStart</code> attribute and (2) the script would raise exceptions earlier when importing modules that are not installed in the system's python.</p>