Activating pyvenv from gitbash for windows

You do not have to worry about the presence of virtual env bash script go to Git bash and use . Scripts/activate or source Scripts/activate as mentioned in answer in this topic Can not activate a virtualenv in GIT bash mingw32 for Windows


There were lots of confusion in many answers and comments here. Some of them said you can simply do . activate, some (@nme) said "You'll get the "No such file or directory" error then since there is only activate.bat and Activate.ps1 which both don't work."

The problem did exist, as documented in this issue. And that issue was eventually fixed at Jan 2017 in Python 3.5.x, 3.6.x onward. Therefore, ONLY Python 3.5.3+, 3.6.1+, 3.7 released AFTER Jan 2017 would have fixed such issue. Possibly Python 2.7.14+ too. This means, if you are still reading this Q&A page, the first thing you would need to do is to check which version of Python you are using, and then probably do an upgrade. (For example, I encountered same issue with one of my old Python 3.6.0 environment, and after upgrading to Python 3.7.2, the problem is gone.)


This is (currently) by design.

In Windows, only the Command Prompt (.bat) and PowerShell (.ps1) scripts are installed. The venv documentation says "The invocation of the script is platform-specific" – see the table in that document listing commands to activate the venv on different platforms. If you look at the venv source code, you can see that it differentiates between Windows and POSIX environments and installs scripts accordingly.

However, there is an open bug that requests that scripts for other shells should also be installed. While waiting for that to possibly be resolved, there is a workaround: you could grab the bash (or other shell) script from your local machine or from the cPython hg repository (direct link to the file) and put it in the Scripts folder next to the Windows-specific ones. You need to change __VENV_DIR__ to the directory where your venv is located, __VENV_BIN_NAME__ to "bin", and __VENV_PROMPT__ to whatever you want the bash prompt to be when the venv is activated (for example, "(env) "). Set permissions, and you should be good to go.