8

I want to run the Windows (Command Prompt) equivalent of

source myvenv/bin/activate

so as to activate and enter into my virtual environment.

3
  • Batch file can automate what you want, but you need to know what activate does, and translate it accordingly.
    – Darius
    May 23, 2018 at 11:30
  • Well I do not have any idea how to do this :/
    – blank_mind
    May 23, 2018 at 11:32
  • If you have solved the problem, please post your answer as an answer in the “Your Answer” box (below). May 23, 2018 at 19:01

5 Answers 5

5

At CMD prompt,it worked by running

myvenv\scripts\activate.bat
3
  • Given this self-answer, the asker appears to be using vanilla Python and virtual environments created with python -m venv some-environment (rather than, say, using conda). May 24, 2018 at 20:15
  • Specific to your question "What is the alternative for source command in cmd?" The equivalent command to "source" is "call".. but it is only used from another batch file. May 14, 2019 at 16:01
  • "The system cannot find the path specified." - not helpful. Aug 11 at 21:55
4

For activating an environment:

activate myenv

for deactivating (all)

deactivate
2
  • 1
    not working says 'activate' not a recognized command
    – blank_mind
    May 23, 2018 at 11:35
  • Did you used conda for creating your environments? Try the command conda from your cmd window.
    – MarianD
    May 23, 2018 at 11:50
1

Go to the the directory where you have the ".bat" file by executing this command:

C:\Users\MyName\Desktop\ProjectsWork\FlaskApplication> cd env\Scripts

Then just call the ".bat" file

\Desktop\ProjectsWork\FlaskApplication\env\Scripts> activate.bat

(env) C:\Users\MyName\Desktop\ProjectsWork\FlaskApplication\env\Scripts>

0

If you want to activate your virtual environment after running:

virtualenv env  

Just run:

env\Scripts\activate

This command will provide you the correct path and the command "source" is not necessary.

Example Image

-1

In windows you don't need any command to directly activate an environment (like a virtual machine) but simply add "activate" or "deactivate" to the end of the path to the environment.

source myvenv/bin/activate

Image for demonstration and example:

enter image description here

just use:

myvenv/bin/activate

Image for demonstration and example:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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