How to activate virtual environment from Windows 10 command prompt
Asked Answered
B

16

33

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.

Brunson answered 23/10, 2017 at 18:26 Comment(1)
this answer may help https://mcmap.net/q/322413/-python-virtualenv-questionsWethington
F
58

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!

Familiarize answered 8/5, 2020 at 12:54 Comment(3)
$ venv\Scripts\activate bash: venvScriptsactivate: command not foundBreughel
Using bash I think what you can do is . venv/Scripts/activate Do note that there is a space after the dot.Kennet
In Windows10 cmd it has to be .\venv\Scripts\activatePaver
F
10

from the command (cmd) prompt:

call venv/Scripts/activate
Fulcher answered 27/8, 2022 at 14:9 Comment(0)
G
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
Guarnerius answered 1/12, 2017 at 23:47 Comment(0)
D
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

Daiquiri answered 12/9, 2021 at 10:30 Comment(0)
M
3

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

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

Melonymelos answered 12/10, 2021 at 13:23 Comment(0)
M
2

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.

Maugre answered 21/1, 2020 at 15:12 Comment(0)
M
1

This works for me from Anaconda prompt,

.\\myvenv\\Scripts\\activate.bat
Mount answered 31/1, 2021 at 18:5 Comment(0)
S
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)

Semiprofessional answered 22/1, 2019 at 7:38 Comment(0)
V
0

Simply you can activate your virtualenv using command: workon myenvname

Valrievalry answered 6/6, 2020 at 6:27 Comment(0)
R
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

Redmond answered 19/9, 2020 at 18:26 Comment(0)
G
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
Godroon answered 5/1, 2021 at 10:46 Comment(0)
C
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 \.

Carcinogen answered 1/3, 2024 at 7:0 Comment(1)
Welcome to Stack Overflow! Before posting an answer, try to check the other answers for duplicate answers that are the same as yours.Olnek
F
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.

Farrel answered 22/4, 2024 at 16:27 Comment(0)
P
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.

Pleasant answered 19/7, 2024 at 21:15 Comment(1)
you should focus on the solution, without telling what was not working for you.Maishamaisie
E
-1

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

address:

your virtual environment name/Scripts/
Excellence answered 23/6, 2023 at 12:46 Comment(0)
K
-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.
Kurdish answered 6/11, 2018 at 19:9 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.