Leonardo the Vinchi
Leonardo the Vinchi

Reputation: 439

How to activate virtual environment from Windows 10 command prompt

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.

Upvotes: 40

Views: 267680

Answers (17)

hit701
hit701

Reputation: 17

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

Upvotes: 1

Julius Reinhold
Julius Reinhold

Reputation: 1

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.

Upvotes: 0

Faitus Joseph
Faitus Joseph

Reputation: 59

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.

Upvotes: 0

Haarshley
Haarshley

Reputation: 1

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 \.

Upvotes: 0

Artin Mevaloo
Artin Mevaloo

Reputation: 1

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

address:

your virtual environment name/Scripts/

Upvotes: -1

Jeremiah Nwosu
Jeremiah Nwosu

Reputation: 151

from the command (cmd) prompt:

call venv/Scripts/activate

Upvotes: 15

Jobin Jose
Jobin Jose

Reputation: 76

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

Upvotes: 4

Alexkha
Alexkha

Reputation: 41

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

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

Upvotes: 4

Mohit
Mohit

Reputation: 1063

This works for me from Anaconda prompt,

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

Upvotes: 1

VikasKM
VikasKM

Reputation: 224

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

Upvotes: 0

alchemist92
alchemist92

Reputation: 1

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

Upvotes: 0

bayard
bayard

Reputation: 709

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!

Upvotes: 64

Shahzaib Chadhar
Shahzaib Chadhar

Reputation: 327

Simply you can activate your virtualenv using command: workon myenvname

Upvotes: 0

Nnamdi Affia
Nnamdi Affia

Reputation: 31

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.

Upvotes: 3

Deep Shah
Deep Shah

Reputation: 131

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)

Upvotes: 0

Vivek
Vivek

Reputation: 1

  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.

Upvotes: -3

thebjorn
thebjorn

Reputation: 27311

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

Upvotes: 8

Related Questions