I created a virtualenv around my project, but when I try to activate it I cannot.
It might just be syntax or folder location, but I am stumped right now.
You can see below, I create the virtualenv and call it venv. Everything looks good, then I try to activate it by running source venv/bin/activate
I’m thinking it might just have to do with my system path, but not sure what to point it to (I do know how to edit the path). I’m on python 7 / windows os, virtual env 2.2.x
Processing dependencies for virtualenv
Finished processing dependencies for virtualenv
c:\testdjangoproj\mysite>virtualenv --no-site-packages venv
The --no-site-packages flag is deprecated; it is now the default behavior.
Using real prefix 'C:\\Program Files (x86)\\Python'
New python executable in venv\Scripts\python.exe
File venv\Lib\distutils\distutils.cfg exists with different content; not overwri
ting
Installing setuptools.................done.
Installing pip...................done.
c:\testdjangoproj\mysite>source venv/bin/activate
'source' is not recognized as an internal or external command,
operable program or batch file.
c:\testdjangoproj\mysite>source venv/bin/activate
'source' is not recognized as an internal or external command,
operable program or batch file.
c:\testdjangoproj\mysite>source mysite/bin/activate
'source' is not recognized as an internal or external command,
operable program or batch file.
c:\testdjangoproj\mysite>
source is a shell command designed for users running on Linux (or any Posix, but whatever, not Windows).
On Windows, virtualenv creates a batch file, so you should run venv\Scripts\activate instead (per the virtualenv documentation on the activate script).
Edit:
The trick here for Windows is not specifying the BAT extension:
For activation you can go to the venv your virtualenv directory
by cd venv.
Then on Windows, type dir (on unix, type ls).
You will get 5 folders include, Lib, Scripts, tcl and 60
Now type .\Scripts\activate to activate your virtualenv venv.
Your prompt will change to indicate that you are now operating within the virtual environment. It will look something like this (venv)user@host:~/venv$.
For windows, type “C:\Users\Sid\venv\FirstProject\Scripts\activate” in the terminal without quotes. Simply give the location of your Scripts folder in your project. So, the command will be location_of_the_Scripts_Folder\activate.
If you see the 5 folders (Include,Lib,Scripts,tcl,pip-selfcheck) after using the virtualenv yourenvname command, change directory to Scripts folder in the cmd itself and simply use “activate” command.
A small reminder, but I had my slashes the wrong way on Win10 cmd. According to python documentation the activate command is: C:\> <venv>\Scripts\activate.bat
When you’re browsing directories it’s e.g. cd .env/Scripts
So to create my venv I used python -m venv --copies .env and to activate .env\Scripts\activate.bat
source command is officially for Unix operating systems family and you can’t use it on windows basically. instead, you can use venv\Scripts\activate command to activate your virtual environment.
If you’re using Windows, use the command “venv\Scripts\activate” (without the word source) to activate the virtual environment. If you’re using PowerShell, you might need to capitalize Activate.
If you are using windows OS then in Gitbash terminal use the following command $source venv/Scripts/activate. This will help you to enter the virtual environment.
If some beginner, like me, has followed multiple Python tutorials now possible has multiple Python versions and/or multiple versions of pip/virtualenv/pipenv…
In that case, answers listed, while many correct, might not help.
The first thing I would try in your place is uninstall and reinstall Python and go from there.