When adding a virtual environment it adds about ~20 megabytes to the project folder, which in my oppinion shouldn't go into the source control.
Is there a best practice what should or shouldn't go into the source control (e.g. should the env folder be skipped completely) and what is the easiest way for a developer to "restore" the virtual environment / packages similiar to NuGet package restore?
depends on whether you are using pip or easy_install, if you are using pip then you can do
pip freeze > requirements.txt
and it will add all of your dependencies into the txt file(your virtualenv must be active) and other devs can install everything by doing
pip install -r requirements.txt
if you are not a fan of the command line PTVS offer a "generate requirements.txt" option when you right click your virtual env and "install from requirements.txt" but for this to work you must keep the requiments.txt at the root of your project(i think)
And yes you should'nt upload your virtualenv to your source control
Good advice @LRPalacios. And yes, the shortcuts in PTVS only work on a top-level file named exactly requirements.txt, though anywhere you can type a package name to install with pip you can also type -r other_reqs.txt to install from a different file.
Thank you for your response. And what is the easiest way to restore the virtual environment itself on the other development machine?

Not sure if the best, but you can right click "Python Enviroments" then "add virtual enviroment" choose the name of the virtual env and folder where you will keep it, then right click the newly created virtual env and choose "install from requirements.txt"
But this only works if I remove the "old" environment, right?
yes, i don't know where did that "old" one came from, if you just downloaded the project it should not be there, since the virtual env is not suppose to be on your source control
Yeah, this is a problem I identifies a while ago but we haven't been able to implement the fix I wanted (which was going to be a single-click recreate/reinstall when the virtualenv is missing). The shortcuts on requirements.txt were a cheap way of getting some of that functionality back.
If you go to add a new virtual environment, you should be able to add it with the same name since it doesn't really exist, and then everything should just come together automatically. We'll even detect the requirements.txt file and install it for you (or not, if you deselect that).
yes, i don't know where did that "old" one came from, if you just downloaded the project it should not be there, since the virtual env is not suppose to be on your source control
The virtual env ist stored within the project file (the folder itself does not exist):
<ItemGroup>
<Interpreter Include="env\">
<Id>{5f6d3af1-2646-4eaa-a0ed-1a20164edb0d}</Id>
<BaseInterpreter>{9a7a9026-48c1-4688-9d5d-e5699d47d074}</BaseInterpreter>
<Version>3.4</Version>
<Description>env (Python 64-bit 3.4)</Description>
<InterpreterPath>Scripts\python.exe</InterpreterPath>
<WindowsInterpreterPath>Scripts\pythonw.exe</WindowsInterpreterPath>
<LibraryPath>Lib\</LibraryPath>
<PathEnvironmentVariable>PYTHONPATH</PathEnvironmentVariable>
<Architecture>Amd64</Architecture>
</Interpreter>
</ItemGroup>
If you go to add a new virtual environment, you should be able to add it with the same name since it doesn't really exist, and then everything should just come together automatically. We'll even detect the requirements.txt file and install it for you (or not, if you deselect that).
Yes (but only after deletion of the "missing" one).
oh ok sorry, i didn't know that, i normally work with the option "from existhing python code" and never had a virtual env created when starting a project this way
but only after deletion of the "missing" one
That shouldn't be necessary, but it looks like you do need to close and reopen the project to get it to refresh. It saves making modifications to the project file.
(We _could_ fix the refresh, but there are a few other factors involved that may not make it such a good idea. I'll make a separate issue so we investigate before our next release.)
If I do that, I get an exception:
I suspect that's some sort of race condition. I have previously seen it happening in automated tests, but I guess it can occur when creating environments too...
Does it occur repeatedly? I can't seem to make it happen in VS 2015, but maybe there's something different about VS 2013 here.
Yes it happens everytime.
At the moment I will stick to the following workflow / workaround:
Since you opened another issue for this anyway, I guess we can close this one?
I'll keep this open until we can look into the exception on VS 2013. We've been pretty busy with a conference for the last few days and haven't had a chance yet.
I think I'm running into something like this- I've been using an environment called env as normal, with the env/ directory excluded from source control. I recently started working with someone else, and after he pulled and opened the project, VS indicated that the environment is missing. If he just removes it from the project, that'll be reflected in the .sln file, right? Is there some way to flag the solution to not track environments at all?
The best thing to do in that situation is actually to create a new environment with the same name ('env'). I really wanted to make it a one-click button to do that, but it never happened unfortunately.
Right now there's no way to not track virtual environments, as we consider these very tightly bound to projects. If you remove all environments it will track your global default, but that isn't able to be a virtual environment.
Good to know- using the same name was my initial best guess, so things should be fine. Thanks for the reply!
Most helpful comment
Good to know- using the same name was my initial best guess, so things should be fine. Thanks for the reply!