Hello folks 👋, If you’ve struggled with activating Python virtual env on Windows this short post is for you.
This is very obvious that activating virtual environment in python using Git Bash on windows is little bit tricky. Also if i want to make venv in python then i always search it on google that how to create venv on windows using git bash ?
. So i decided to write an article that helps others to understand how this venv works in git bash.
On my machine i have python 3.9 installed and i'm using vs code for all my projects with built in git bash terminal. From git bash if we try to activate virtualenv
with ./Scripts/activate
after running command python -m venv
, it not worked (only worked with command prompt).
If you are using git bash on windows then first navigate to your project folder, use ls
to list the content of the folder and be sure you see the Scripts
.
Change directory to Scripts
using cd Scripts
, once you're in the Scripts path, use . activate
to activate virualenv
. Don't forgot the space after the dot.
Be sure to cd
out of the Scripts
directory and return back to your project folder after activating venv.
# Commands for activating virtual env on git bash
python -m venv . # create venv in current directory [add "." or path here]
cd Script # change directory to Scripts folder
. activate # run this command to activate venv and change directory back to project folder
If you like this article then please let me know in comments or find me on Twitter.