38

I'm trying to create and activate a virtual environment, using Windows 10 command prompt. I know that virtualenv is installed correctly, as the command

virtualenv venv

Works. I've navigated to my virtualenv download, Downloads\venv\Scripts, and am trying to activate my virtual environment venv. I've tried

venv activate

Which doesn't work since Windows doesn't recognize venv as a command. I've also tried

virtualenv venv activate

Which also doesn't work since virtualenv is saying that "venv activate" isn't a valid argument.

1

17 Answers 17

62

Use the activate script in the Scripts directory of your virtual environment:

> venv\Scripts\activate

This will activate your virtual environment and your terminal will look like this depending on the directory you're in:

(venv) C:\Users\acer\Desktop>

I hope this helps!

3
  • 1
    $ venv\Scripts\activate bash: venvScriptsactivate: command not found Commented May 18, 2021 at 16:37
  • 1
    Using bash I think what you can do is . venv/Scripts/activate Do note that there is a space after the dot.
    – KiritoLyn
    Commented Sep 11, 2021 at 11:35
  • 7
    In Windows10 cmd it has to be .\venv\Scripts\activate
    – pegah
    Commented Oct 26, 2021 at 10:44
11

from the command (cmd) prompt:

call venv/Scripts/activate
0
8

If you're using virtualenvwrapper-win, and using the DOS command prompt (as opposed to e.g. Powershell), then new virtualenvs are created using:

mkvirtualenv myenv

and activated using

workon myenv

You should define the environment variable WORKON_HOME to point to where you want you virtualenvs to reside.

If you've installed virtualenvwrapper-win>=1.2.4 then the virtualenvwrapper command will give you a list available commands:

go|c:\srv> virtualenvwrapper

 virtualenvwrapper is a set of extensions to Ian Bicking's virtualenv
 tool.  The extensions include wrappers for creating and deleting
 virtual environments and otherwise managing your development workflow,
 making it easier to work on more than one project at a time without
 introducing conflicts in their dependencies.

 virtualenvwrapper-win is a port of Dough Hellman's virtualenvwrapper to Windows
 batch scripts.

 Commands available:

   add2virtualenv: add directory to the import path

   cdproject: change directory to the active project

   cdsitepackages: change to the site-packages directory

   cdvirtualenv: change to the $VIRTUAL_ENV directory

   lssitepackages: list contents of the site-packages directory

   lsvirtualenv: list virtualenvs

   mkproject: create a new project directory and its associated virtualenv

   mkvirtualenv: Create a new virtualenv in $WORKON_HOME

   rmvirtualenv: Remove a virtualenv

   setprojectdir: associate a project directory with a virtualenv
   toggleglobalsitepackages: turn access to global site-packages on/off

   virtualenvwrapper: show this help message

   whereis: return full path to executable on path.

   workon: list or change working virtualenvs
4

From the directory where you have your virtual environment (e.g. myenv)

you need to run the following command: .\myenv\Scripts\activate

4

Go to the folder where you have created the virtual environment in cmd and enter the command .\venv\Scripts\activate It will activate the virtual env in windows

3

When you use "virtualenv" to create an env, it saves an "activate.bat" file in the scripts folder originating from the directory you ran the first command. E.g if you ran the command virtualenv env from C:/Users/Name/Documents/..., the .bat will be located in C:/Users/Name/Documents/.../env/scripts/activate.bat. You can run it from there.

0
1

This works for me from Anaconda prompt,

.\\myvenv\\Scripts\\activate.bat
1

If you don't change powershell policy, please set following command. (*If you have already changed powershell policy,you don't need the powershell command)

PowerShell Set-ExcecutionPolicy Remotesigned CurrentUser
py -m venv venv
venv\Scripts\Activate.ps.1

Abobe code, lower case will be allowed. And, those commands will be used in Win10 and Win11

0

Make sure the Python Scripts folder is in your environment variables.

Usually the path is: "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\Scripts" (Change "admin" to your windows username and "Python37-32" path according to your python version)

0

Simply you can activate your virtualenv using command: workon myenvname

0

You can also create a command-line script like this -

@echo off
CD\
CD "C:\Users\[user name]\venv\Scripts" 
start activate.bat
start jupyter notebook

Save this in a notepad file with an extension ".cmd". You are ready to go

0

if you have anaconda installed then open anaconda terminal and type

> conda env list              # for list of environment you already have
> conda activate {env_name}   # to activate the environment
0

Here are the steps that I followed in order to create virtual environment in Windows without any error:

  1. python -m venv (virtual-env-name)
  2. .\(virtual-env-name)\Scripts\activate

Note: There is no space in between . and \.

1
  • Welcome to Stack Overflow! Before posting an answer, try to check the other answers for duplicate answers that are the same as yours.
    – pigrammer
    Commented Mar 4 at 14:24
0

In Windows 10 Pro I used the below command to create the virtual environment and activate the same. I use virtual environment to run my Python programs. Run the below commands in command prompt.

 >py -m venv venv
 >.\venv\Scripts\activate
 (venv) >py abc.py

Virtual environment name is venv.

0

For me, the reason it didnt work was that i hadnt yet created a python file in the same directory as the venv directory is also located. Only after creating the python file did the activation file and all the associated stuff show up, and i could activate it.

1
  • you should focus on the solution, without telling what was not working for you.
    – Giacomo
    Commented Jul 20 at 17:13
-1

first open a command line. Then drop active.bat file from this address to your command line.

address:

your virtual environment name/Scripts/
-3
  1. start python 3.7
  2. python -m virtualenv
    "You must provide a DEST_DIR"
  3. python -m venv demodjango("demodjango is file name)"
  4. activate.bat
  5. pip install django
  6. django-admin.py startproject demo1 (demo1 is my project)
  7. python manage.py runserver
    Performing system checks...
  8. After doing this on a command prompt, you will get an URL. Click on that and you will see a message in the browser window that Django has been properly installed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.