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

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

+6
source share
4 answers

I found that if:

  • main.py is installed as a startup file,
  • in the project properties โ†’ debug tab โ†’ field โ€œinterpreter pathโ€, I put the path C: ... \ env \ Scripts \ python.exe (i.e. the python executable for virtualenv)

It works!

+4
source

Python Tools for Visual Studio (PTVS) 2.0 is now missing, you can add virtualenv in it.

  • Open Solution Explorer: View> Solution Explorer

  • Right-click on "Python Environments" and select "Add Virtual Environment"

Here is a video showing how to do this.

+4
source

I usually point Visual Studio to a custom startup.py script, any other batch files that I can 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 the project
  • The properties
  • Are common
  • In the "Startup File" section, enter startup.py (whatever)
  • Make sure your working directory is correct.
+3
source

Full support for Virtual Env is included with PTAS 2.0 Beta / RTM. See http://pytools.codeplex.com for news / updates. Early support for PTVS 2.0 Alpha, available now.

+1
source

Source: https://habr.com/ru/post/922196/


All Articles