title: Crontab to launch python script on raspberry pi causes import error
body: <p>I am running <code>Ubuntu Mate</code> on my Raspberry PI.  I wrote a web <strong>scraper</strong> in Python that I want to run once a day.  I figured using <code>sudo crontab -e</code> would be a good way to do way. The problem that I'm having is when the <code>cronjob</code> launches my python script, the python script throws an import error and doesn't run.  However, when I execute the python script directly from the command line, it runs without issue.</p>
  <p>I was reading that some people use a shell script to launch they python script, so I tried that as well.  Again, it works as expected when I execute the shell script directly from the command line, but does not work when executed by the <code>cronjob</code>.</p>
  <p>For testing purposes, right now I have the <code>cronjob</code> to execute every minute until I figure out what's going on.  Once it works as expected, I'll change the time that it executes to something closer to what I want.</p>
  <p>To give you an idea of what my files look like, check it out below.  As you can see, all of the files that need to run have execute prilivages.</p>
  <h1>web_scraper.py</h1>
  <pre><code>#!/usr/bin/env python
  
  import click
  import logging
  import os
  from datetime import datetime
  from bs4 import BeautifulSoup as bs
  import re
  import urlparse
  ...
  </code></pre>
  <h1>start.sh</h1>
  <pre><code>#!/bin/bash
  
  cd /home/elmer/
  
  python web_scraper.py
  </code></pre>
  <h1>sudo crontab -e</h1>
  <pre><code>* * * * * sh /home/elmer/start.sh &gt;&gt; /home/elmer/cron.log 2&gt;&amp;1
  </code></pre>
  <h1>cron.log</h1>
  <pre><code>Traceback (most recent call last):
    File &quot;web_scraper.py&quot;, line 6, in &lt;module&gt;
      import click
  </code></pre>
  <h1>ls -lh</h1>
  <pre><code>(py27)elmer@elmer-rpi:$ ls -lh
  total 56K
  -rw-rw-r-- 1 elmer elmer 2.9K Mar 17 20:38 cron.log
  -rwxrwxrwx 1 elmer elmer 8.2K Mar 16 09:54 web_scraper.py
  -rwxrwxrwx 1 elmer elmer   64 Mar 17 20:02 start.sh
  </code></pre>