Activating pyvenv from gitbash for windows

I use gitbash for windows (7, 64 bit). I tried creating venv using the venv built-in module using python 3.4 by calling python -m venv venv , and it was created successfully, but the resulting venv does not contain bash to activate the script, only .bat and .ps1 .

The virtualenv library for python 2.6.6 (version 13.0.1) created the following four files in the venv/Scripts/ folder: activate , activate.bat , activate.ps1 and activate_this.py .

Since the gitbash console cannot use bat or powershell scripts, and I really don't want to return to the Windows cmd prompt or to the VM, is there a way to get pyvenv to create a shell script for me while I'm on windows?

+9
python windows git-bash virtualenv
source share
6 answers

There has been a lot of confusion in many of the answers and comments. Some of them said that you can just do it . activate . activate . activate . activate , some (@nme) said "You will not get the" There is no such file or directory "error, since there is only activate.bat and Activate.ps1 that both do not work."

The problem really existed, as documented in this release . And this problem was eventually fixed in January 2017 in Python 3.5.x, 3.6.x and beyond. So ONLY Python 3.5. 3+, 3.6. 1+, 3.7, released AFTER January 2017, would fix such a problem. Maybe Python 2.7. 14+ too. This means that if you are still reading this question and answer page, the first thing you need to do is check which version of Python you are using, and then probably upgrade. (For example, I ran into the same problem with one of my old Python 3.6.0 environments, and after upgrading to Python 3.7.2 the problem disappeared.)

+5
source share

You do not need to worry about having a virtual env bash script switch to Git bash and use . Scripts/activate . Scripts/activate or source Scripts/activate as indicated in the answer to this question Unable to activate virtualenv in git bash mingw32 for Windows

+8
source share

This is (currently) by design.

On Windows, only command line scripts (.bat) and PowerShell (.ps1) are installed. The venv documentation says: “The invocation of the script is platform dependent” - see the table in this document listing the commands for activating venv on different platforms. If you look at the venv source code, you will see that it distinguishes between Windows and POSIX environments and sets up the scripts accordingly.

However, there is an open bug that requires scripts for other shells to be installed as well. Expecting that this will probably be possible, you can use the bash (or other shell) script from your local machine or with the cpython hg repository ( direct link to the file ) and place 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__ so that you want the bash prompt when venv is activated (for example, "(env)"). Set permissions and you should be good to go.

+3
source share

The following code explains how to configure and run virtualenv named env_project inside a folder named project in Git Bash:

 mkdir project cd project/ virtualenv env_project . activate env_project/ 
+1
source share

this worked for me:

 . activate 
+1
source share

I have python 3.7 installed on Windows, and I still cannot activate virtualenv from Gitbash using ./Scripts/activate although it worked from Powershell after running Set-ExecutionPolicy Unrestricted in Powershell and changing the Yes for Everyone parameter.

I don’t like Powershell and I like to use Gitbash, so to activate virtualenv in Gitbash, first go to your project folder, use ls to view the contents of the folder and make sure that you see “Scripts”. Change the directory to "Scripts" using cd Scripts as soon as you use the "Scripts" path . activate . activate . activate . activate to activate virtualenv . Do not forget the space after the period.

0
source share

All Articles