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.
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.
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.
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
To create a virtual environment,
decide upon a directory where you want to place it, and run the venv module as a script with the directory path:
python3 -m venv tutorial-env
This will create the tutorial-env directory if it doesn’t exist, and also create directories inside it containing a copy of the Python interpreter and various supporting files.
A common directory location for a virtual environment is .venv. This name keeps the directory typically hidden in your shell and thus out of the way while giving it a name that explains why the directory exists. It also prevents clashing with .env environment variable definition files that some tooling supports.
Once you’ve created a virtual environment, you may activate it.
On Windows, run:
tutorial-env\Scripts\activate.bat
On Unix or MacOS, run:
source tutorial-env/bin/activate
some times the environment will not active because users are not allowed to run scripts in the current system so you should
-Set-ExecutionPolicy -Scope CurrentUser Unrestricted
now you are allowed to run scripts on your system then try this again
py -m pip install --user virtualenv
For creating new environment:
py -m venv myproject
To activate your virtual environment:
.\myproject\Scripts\activat
If you have a Windows computer (and installed the Windows version virtualenvwrapper-win
), make sure you add the Scripts
folder to the path. As per the installation instructions:
To use these scripts from any directory, make sure the Scripts subdirectory of Python is in your PATH. For example, if python is installed in C:\Python27, you should make sure C:\Python27\Scripts is in your PATH.
Here's some decent instructions on how to edit your path. Nowadays you can probably create a new entry after selecting to edit the path environment variable. That new entry should just be the location of the Scripts folder (including the Scripts folder). No need to add semicolons to a super long path name - it generally does that for you nowadays. You'll probably have to restart your computer for it to take effect.
You can find out where your Python is installed here. If you are on Windows and installed Python via the Microsoft Store, you won't see a Scripts folder. In that case, install Python from the Python website, not from the Microsoft Store.