3

While I was trying to execute the mkvirtualenv command on the command prompt, I was getting this error:

C:\Users\mukesh>mkvirtualenv myproject 
'mkvirtualenv' is not recognized as an internal or external command, operable program or batch file.
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
  • 3
    Possible duplicate of [What is the reason for "X is not recognized as an internal or external command, operable program or batch file"?](https://stackoverflow.com/questions/41454769/what-is-the-reason-for-x-is-not-recognized-as-an-internal-or-external-command) – aschipfl Jun 26 '19 at 17:33

2 Answers2

15

For Python 3.3 or newer, Commands for installing, creating and activate virtual environment has been changed.

You can install virtual environment using pip:

py -m pip install --user virtualenv

For creating new environment:

py -m venv myproject

To activate your virtual environment:

.\myproject\Scripts\activate

After activating virtual environment, You’ll see “(myproject)” next to the command prompt.

Rajan Tejani
  • 151
  • 1
  • 3
  • But what is the spirit of using additional switch i.e. --user?Is not it making complex the older simpler one. – SIslam Jul 08 '20 at 12:01
  • Thank you, this worked! The other answer that is directly from django docs did not work for me. https://docs.djangoproject.com/en/2.2/howto/windows/ – Azhar Ansari Nov 23 '21 at 05:07
9

You may find this link useful, as it shows the steps required. It is possible you have simply missed the earlier steps, leading to the error.

The below information is from: https://docs.djangoproject.com/en/2.2/howto/windows/

This will run you through the creation of a virtual environment on Windows:

Install virtualenv and virtualenvwrapper¶

virtualenv and virtualenvwrapper provide a dedicated environment for each Django project you create. While not mandatory, this is considered a best practice and will save you time in the future when you’re ready to deploy your project. Simply type:

pip install virtualenvwrapper-win

Then create a virtual environment for your project:

mkvirtualenv myproject

The virtual environment will be activated automatically, and you’ll see “(myproject)” next to the command prompt to designate that. If you start a new command prompt, you’ll need to activate the environment again using:

workon myproject
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Compoot
  • 1,998
  • 3
  • 25
  • 54