103

After I installed Python and Djangom, I'm trying to use virtualenv for django project purpose using virtualenv. I installed virtualenv using pip.

pip install virtualenv # got install successfully

When I tried to run it, I got the error message

C:\Users\gshiv\Desktop\DjangoProject>virtualenv
'virtualenv' is not recognized as an internal or external command,
operable program or batch file.
pppery
  • 3,731
  • 22
  • 33
  • 46
ShivaGuntuku
  • 5,274
  • 6
  • 25
  • 37

24 Answers24

128

steps: - go to where you want create django app on that folder.

then run this command on command prompt : python -m virtualenv .

(eg. C:\Users\gshiv\Desktop\django>python -m virtualenv .)

where django is the my folder i want run virtualenv and .(dot) indicates virtualenv install all it's folder in django folder otherwise you can use other folder name instead .(dot) this time virtulenv creates a folder in main folder(django) .

  • after running this command: run .\scripts\activate now you can see this type of line on cmd-prompt (django) C:\Users\gshiv\Desktop\django>
  • i.e main folder name before the source path. now you can install any modules for your project that belongs to that main folder only.

pip install django works fine.

prashanth manohar
  • 531
  • 1
  • 13
  • 30
ShivaGuntuku
  • 5,274
  • 6
  • 25
  • 37
49

If you can not find your virtualenv command in the windows console/terminal after installing it with pip, try this to make your environment

python -m virtualenv <nameOfEnv>

If you want to use a specific version of python, initialize it like this

python -m virtualenv <nameOfEnv> -p=<C:/path/to/python/version3.x.x/python.exe>

When using windows for first installation, you can use python from WindowsApp

Tirbo06
  • 655
  • 6
  • 11
41

Run pip uninstall virtualenv and then pip install virtualenv

Sergey K.
  • 1,855
  • 9
  • 12
  • 1
    I had similar problem, found this SO question. Then noticed this error message. WARNING: The script virtualenv.exe is installed in 'C:\Users\bmt\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts' which is not on PATH. add the dir to the environment path, edit cmd and re-enter cmd. also: use which to identify what PATH is doing. ie which python – CodingMatters Mar 27 '20 at 01:30
  • 1
    Sometimes, re-install is the way to solve the issue :D. Thank you guy – Redplane Oct 13 '20 at 06:15
  • Second time install virtualenvv as `root` or on windows open terminal/cmd using "Run as Administrator" – Nishan Dec 21 '22 at 04:54
25

There are three points that you need to consider:

  • Make sure that in the windows PATH variable there is an entry with your python installation and the scripts subfolder eg: C:\Program Files (x86)\Python36-32\ and C:\Program Files (x86)\Python36-32\Scripts\
  • When using pip install virtualenv, make sure that you run cmd as administrator. Otherwise, there might an access denied error during installation and virtualenv will not be installed properly.
  • Make sure that virtualenv has been installed correctly. Check in the python scripts subfolder - there must exist an .exe named virtualenv.exe. If not, uninstall will pip uninstall virtualenv and install again.
Charidimos
  • 588
  • 6
  • 7
  • 5
    Making sure that I was running in cmd (not powershell) as admin, I uninstalled virtualenv and reinstalled it. Worked like a charm – Malcolm Anderson Oct 23 '17 at 07:17
  • 1
    For some reason, open the cmd as administrator, then *uninstall" the virtualenv and install again has work for me too. – syam Feb 14 '22 at 05:23
17

When I ran the pip install virtualenv command I got:

Requirement already satisfied: virtualenv in c:\directory\to\appdata\roaming\python\python36\site-packages

so I tried forcing upgrade:

pip install --upgrade --force virtualenv
StevenWernerCS
  • 839
  • 9
  • 15
hestellezg
  • 3,309
  • 3
  • 33
  • 37
14

py -3 -m venv venv

try using the above command.

virtualenv venv

will work on only older version of python

praveen kumar
  • 161
  • 1
  • 4
13

Use

python -m venv abc

Where abc is the name of the virtual environment

Kachkol Asa
  • 367
  • 3
  • 6
10

Run CMD as administrator and then enter

pip uninstall virtualenv

then re-run CMD as administrator and run

pip install virtualenv
Sandeep Patil
  • 1,272
  • 3
  • 9
  • 12
Firenze
  • 365
  • 2
  • 11
4
  • Step 1: Run pip uninstall virtualenv.
  • Step 2: Run pip install virtualenv.
  • Step 2.1: Run virtualenv to check if it's now working...
  • Step 3: Still not working? Go to your prevouis console log to find where it says "WARNING: The script virtualenv.exe is installed in 'C:\Users\username\AppData\Roaming\Python\Python310\Scripts' which is not on PATH."
  • Step 4: Copy the specified path from the warning message.
  • Step 5: Search for and open "System Properties" on your PC.
  • Step 6: Click the Advance tab, and then the Environment Variables Button on the bottom right.
  • Step 7: Click the variable value "Path" and then click edit.
  • Step 8: In the Edit Environment variable window, click new then paste your path in any slot.
  • Step 9: MAKE SURE you click OK twice and not to just exit out.
  • Step 10: Reboot terminal and check again.
Johnny Bravo
  • 163
  • 11
3

Use py -m virtualenv Your_Folder_Name

wovano
  • 4,543
  • 5
  • 22
  • 49
3

You just need to reinstall virtualenv. First of all you need to uninstall virtualenv with this command.

pip uninstall virtualenv

Then just reinstall with this command.

pip install virtualenv

Solution-1: python -m venv name_of_virtual_environment

E:\code\python\tvenv>python -m venv myenv

E:\code\python\tvenv>cd myenv\Scripts\

E:\code\python\tvenv\myenv\Scripts>activate.bat

(myenv) E:\code\python\tvenv\myenv\Scripts>deactivate.bat
E:\code\python\tvenv\myenv\Scripts>

Solution-2: py -3 -m venv name_of_virtual_environment

E:\code\python\tvenv>py -3 -m venv myenv

E:\code\python\tvenv>cd myenv\Scripts

E:\code\python\tvenv\myenv\Scripts>activate.bat

(myenv) E:\code\python\tvenv\myenv\Scripts>deactivate.bat
E:\code\python\tvenv\myenv\Scripts>
Optimus Prime
  • 308
  • 6
  • 22
2

To install to a specific folder e.g E:\publish

pip install virtualenv

virtualenv .

Rohan Devaki
  • 2,931
  • 1
  • 14
  • 22
MANOJ G
  • 632
  • 7
  • 7
2

Try to run

    PowerShell.exe -command "./venv/Scripts/activate"
  • Hi, there are already 18 other answers on the topic. How does your answer build up on the other answers that already propose similar means to activate venv? – Simas Joneliunas Feb 12 '22 at 00:07
  • 1
    @SimasJoneliunas In my case "./venv/Scripts/activate" doesn't work if you run it from cmd. So there is a prefix "PowerShell.exe -command" which indicate usage of PowerShell. This was a solution in my problem. – ResistorsSmoker Feb 12 '22 at 16:41
1

For windows First, install -> pip install virtualenvwrapper-win Then setup -> mkvirtualenv myproject Then you see the list of virtual environment To see it you write-> lsvirtualenv For working this environment we write -> workon myproject

1

I had this same issue using python3.

The solution was to use the python3 -m virtualenv . command.

0

Try executing virtualenv.exe from its absolute path, like in my case i found it in C:\Users\<your user>\AppData\Roaming\Python\Python37\Scripts\virtualenv.exe.

I tried this and it worked, here refer the logs as follows:

Using base prefix c:\\users\\<user>\\appdata\\local\\programs\\python\\python37-32 New python executable in C:\somedir\dir2\dir3\ML_1\ml\env\Scripts\python.exe Installing setuptools, pip, wheel... done.

Rohan Devaki
  • 2,931
  • 1
  • 14
  • 22
Vishal Garg
  • 3
  • 1
  • 3
0

This almost works for all

  1. Open Command Prompt, navigate it to the Envs folder, run "env_name\Scripts\activate"
  2. Check whether virtualenv is installed or not, if not install it:
    • pip install virtualenv
    • pip install virtualenvwrapper-win
  3. Game On. Check on your IDE.
Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35
Ram Potabatti
  • 67
  • 1
  • 3
0

I got this error too but I figure it out. you just have to open PowerShell as administrator and then write following command Set-ExecutionPolicy unrestricted then type A. you are all set! now uninstall the packages and re-install them. Now if you write flask --version or virtualenv --version There will be no error at all.

l33tHax0r
  • 1,384
  • 1
  • 15
  • 31
0

Windows

If you want to use the lsvirtualenv command with virtualenv, follow the steps below.

Incorrect:

python -m pip install virtualenv 
python -m pip install virtualenvwrapper

Correct:

python -m pip install virtualenv
python -m pip install virtualenvwrapper-win

Basic Uses

Then, to create a virtual environment:

mkvirtualenv youVirtualEnvironmentName
  • It will be activated automatically:
    C:\Users\YourUserName (youVirtualEnvironmentName) λ
    

First, to access an existing virtual environment:

C:\Users\YourUserName λ workon youVirtualEnvironmentName

Next, to exit the currently active virtual environment:

C:\Users\YourUserName (youVirtualEnvironmentName) λ deactivate

Finally, to list all your virtual environments:

C:\Users\YourUserName λ lsvirtualenv

dir /b /ad 'C:\Users\YourUserName\Envs'
==================================================================
youVirtualEnvironmentName

Full Array
  • 769
  • 7
  • 12
0

Below command worked for me:

python -m virtualenv virtualenvname

However, after creating a virtual environment, I could not install any package into it and was getting error: "ERROR: Can not perform a '--user' install. User site-packages are not visible in this virtualenv."

To resolve that, I have had to update the pyvenv.cfg file from the virtual environment folder as below:

include-system-site-packages = true

Reference: https://github.com/microsoft/vscode-python/issues/14327


Update


I ran into all sorts of issues like not able to run django-admin command. I have installed python 3.10 from windows store as running python command was taking me to windows store. I already had python 3.11 hence I uninstalled 3.10 and then:

I have found that the path for my python installation was not added into my environment variables (PATH).

  • I have added the path for my python installation and closed any existing command prompt (To allow it to use new environment variables)
  • Deleted the existing django environment and created it again simply using command: "virtualenv virtualenvname" and it worked for me this time.
  • Activate the evironment: virtualenvname\Scripts\activate
  • django-admin command worked for me this time.
0

In my cases, the problem is that I had install virtualenv using a normal user.

Switch to Admin or Administrator (if using Windows OS), then run

pip uninstall virtualenv and pip install virtualenv

Close the Admin or Administrator terminal and open the terminal with your normal user and run

virtualenv myenv

It should create the python virtual environment successfully.

-1

Make sure that virtualenv has been installed correctly. Check in the python scripts subfolder - there must exist an .exe named virtualenv.exe. If not, uninstall will pip uninstall virtualenv and install again.

Rohan Devaki
  • 2,931
  • 1
  • 14
  • 22
-1

1)First Way as

python -m virtualenv name_of_virtual_environment


OR


2)Second Way as

py -3 -m venv name_of_virtual_environment

  • 5
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 17 '21 at 12:03
  • 2
    This is the same as the other, older answers. – Gino Mempin Sep 23 '22 at 10:24
-2
  1. Open a cmd or ps with run as admin.
  2. Now run pip uninstall virtual.
  3. pip install virtual.
  4. Done :D

Implementation:

  1. Go to the directory where you want to make a python env.
  2. type: virtualenv myEnv
  3. beep bop boop done.

ps: Always use cmd or powershell with run as admin if you're installing some new package.

The Flash
  • 59
  • 7