Can not activate a virtualenv in GIT bash mingw32 for Windows

PythonGitBashVirtualenvGit Bash

Python Problem Overview


When I try to activate my virtualenv from GIT bash mingw32 I do not get the expected response.

NOTE: py is the folder for Python projects in my Google Drive folder. hy is the virtualenv folder that was made when I ran virtualenv --distribute hy.

s3z@s3z ~/Google Drive/py/hy
$ Scripts/activate

So you see, there is no expected (hy) that appears before s3z@s3z ~/Google Drive/py/hy

s3z@s3z ~/Google Drive/py/hy
$ Scripts/activate.bat
Scripts/activate.bat: line 1: @echo: command not found
Scripts/activate.bat: line 4: syntax error near unexpected token `('
Scripts/activate.bat: line 4: `if not defined PROMPT ('

And when targeting the actual file name activate.bat I get error messages. Then I try deactivating to see what happens cause I thought maybe virtualenv was activated but hidden.

s3z@s3z ~/Google Drive/py/hy
$ Scripts/deactivate.bat
Scripts/deactivate.bat: line 1: @echo: command not found
Scripts/deactivate.bat: line 3: syntax error near unexpected token `('
Scripts/deactivate.bat: line 3: `if defined _OLD_VIRTUAL_PROMPT ('

s3z@s3z ~/Google Drive/py/hy
$ Scripts/deactivate
sh.exe": Scripts/deactivate: No such file or directory

Any ideas?

Python Solutions


Solution 1 - Python

Doing Scripts/activate runs the script in a new instance of the shell, which is destroyed after the script execution. To run the script in your current shell, use either . Scripts/activate or source Scripts/activate.

Scripts/activate.bat does not work here because it is written in Batch, Windows cmd.exe language, and not Bash.

Solution 2 - Python

On Windows10, you could go in the directory of your virtualenv where the Scripts folder is placed then enter the below command

source ./Scripts/activate

Note the .(dot) without this it was giving error to me when I use it like above mentioned then the solution provided by Pierre worked for me.

Solution 3 - Python

How to activate then deactivate a venv with Git Bash


To access your python in Windows 10, you need to add the .exe when creating the virtual environment.

$ python.exe -m venv Scripts

Then you can move into the Scripts folder you created for the virtual environment.

$ cd Scripts/

Now you have to call on it to activate the virtual environment.

$ source ./Scripts/activate

When you are done you just deactivate the virtual environment.

$ deactivate

Screenshot how to activate/deactivate Git Bash venv


Solution 4 - Python

I had the same error: in your bash run, this commend: source venv/Scripts/activate then check if it works using this commend: pip -V I hope that is useful.

Solution 5 - Python

Just do . Scripts/activate in your virtual environment folder enter image description here

Solution 6 - Python

Danyal Abbasi@DESKTOP-7I43AM4 MINGW64 /e/Django-projects/studybudproject/studybud/Scripts
$ . activate
(studybud)
Danyal Abbasi@DESKTOP-7I43AM4 MINGW64 /e/Django-projects/studybudproject/studybud/Scripts
$ deactivate

Danyal Abbasi@DESKTOP-7I43AM4 MINGW64 /e/Django-projects/studybudproject/studybud/Scripts
$

Solution 7 - Python

I recently had this problem and i found the solution for this. after you have done

$ cd Scripts

after this you should just simply type

$ source activate

and this will activate your venv

to deactivate just type

$ deactivate

and you venv is deactivated

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser883807View Question on Stackoverflow
Solution 1 - PythonPierre BourdonView Answer on Stackoverflow
Solution 2 - PythonAman TandonView Answer on Stackoverflow
Solution 3 - PythonNathan WeilerView Answer on Stackoverflow
Solution 4 - PythonAyoub AarabView Answer on Stackoverflow
Solution 5 - Pythonsiaka karlView Answer on Stackoverflow
Solution 6 - PythonDanyal MuneerView Answer on Stackoverflow
Solution 7 - Pythonanil gurjarView Answer on Stackoverflow