How to run a python script with Python Tools for Visual Studio in a virtualenv?

Balmat picture Balmat · Aug 6, 2012 · Viewed 30.3k times · Source

I don't know how to run the activate.bat in a Python Tools for Visual Studio Project. I have a directory environment in my project with my virtualenv. But, I don't know how I can run ./env/Scripts/activate.bat before the project run my main python script.

Answer

Aesthete picture Aesthete · Aug 6, 2012

I usually point Visual Studio to a custom startup.py script, any other batch files I can then run using:

# startup.py
import os
import main.py # Whatever your main script is
os.system('activate.bat') # Call your batch files.
main.run() # Call whatever you need to from your main script.

In Visual Studio

  • Right click on project
  • Properties
  • General
  • Under Startup File, put startup.py (whatever)
  • Make sure your working directory is correct