title: Python script to activate and keep open a Virtualenv
body: <p>I need a python script that will activate a virtualenv, run another python program inside the virtualenv, and then close the virutalenv after the second python program closes. Here is my code:</p>
  
  <pre><code>import os
  import subprocess
  from subprocess import Popen
  
  activate_dir = "C:/Users/JohnDoe/theprogram/Scripts/"
  os.chdir(activate_dir)
  subprocess.Popen(["activate.bat"])
  
  cal_dir = "C:/Users/JohnDoe/theprogram/"
  os.chdir(cal_dir)
  os.system('python program_file.py')
  </code></pre>
  
  <p>However, when this code run, I get an import error from the <code>program_file</code> which means the virtualenv is not activated. How can I fix this?</p>
  
  <p>Thanks</p>
  
  <p><strong>Edit:</strong>
  This is on a Windows environment. </p>