24

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.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
  • this answer may help https://stackoverflow.com/questions/4527958/python-virtualenv-questions – TylerH Oct 23 '17 at 18:54

13 Answers13

48

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!

tim-kt
  • 304
  • 5
  • 17
bayard
  • 529
  • 5
  • 7
7

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
thebjorn
  • 26,297
  • 11
  • 96
  • 138
4

from the command (cmd) prompt:

call venv/Scripts/activate
D.L
  • 4,339
  • 5
  • 22
  • 45
3

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

pegah
  • 791
  • 8
  • 15
Jobin Jose
  • 31
  • 2
3

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

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

Alexkha
  • 31
  • 1
1

This works for me from Anaconda prompt,

.\\myvenv\\Scripts\\activate.bat
Mohit
  • 1,045
  • 4
  • 18
  • 45
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)

Deep Shah
  • 101
  • 2
  • 7
0

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.

Jawad
  • 11,028
  • 3
  • 24
  • 37
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
VikasKM
  • 212
  • 3
  • 7
-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.
Simon Zyx
  • 6,503
  • 1
  • 25
  • 37
Vivek
  • 1
  • 1
  • 4