title: How can I make an executable python script run inside the current virtual environment?
body: <p>So what I'm trying to do is have an executable python script so that I can link to it on my path and run it from anywhere, but I need to run it within a virtual environment locally.</p>
  
  <p>Currently I have a symbolic link in /usr/local/bin -> ~/dev/project/tools/rest_client.py</p>
  
  <p>Inside the project directory the permissions are:</p>
  
  <pre><code>-rwxr-xr-x  1 luke  staff  3229 Dec  3 10:21 rest_client.py 
  </code></pre>
  
  <p>The rest-client file</p>
  
  <pre><code>#!/Users/luke/Envs/py2.7/bin/python
  
  def main():
     #do stuff
  </code></pre>
  
  <p>I can run it from any directory like this when I run <code>rest-client</code></p>
  
  <p>I would like to be able to check this file into a git repo and share it with others, without hardcoding the virtualenv into the file, but to still be able to execute it from anywhere on my machine.</p>
  
  <p>If I change the first line to </p>
  
  <pre><code>#!/usr/bin/python
  </code></pre>
  
  <p>Then it wont run in the virtual environment unless I execute it via</p>
  
  <pre><code>workon py2.7
  python ~/dev/project/tools/rest_client.py
  </code></pre>
  
  <p>Is there a proper way to do this is UNIX without using something like an alias?</p>