virtualenv is a tool to create isolated Python environments. You can read more about it in the Virtualenv documentation. This article provides a quick summary to help you set up and use a virtual environment.
Where’s My Python?¶
Sometimes the trickiest part of setting up a virtual environment on Windows is finding your python distribution. If the installer didn’t add it to your PATH variable, you may have to go looking. If you downloaded and installed python from python.org and accepted all the defaults during installation, python.exe may be found in one of the following locations:
64-bit (Preferred)¶
C:\Users\%username%\AppData\Local\Programs\Python\Python36\python.exe
32-bit¶
C:\Users\%username%\AppData\Local\Programs\Python\Python36-32\python.exe
Install virtualenv¶
If you try to run virtualenv and find it isn’t present, you can install it using pip.
virtualenv.exe will likely now be found in your python installation directory under the Scripts subdirectory.
Create a Virtual Python Environment¶
cd to your project directory and run virtualenv to create the new virtual environment.
The following commands will create a new virtual environment under my-project/my-venv.
cd my-project virtualenv --python C:\Path\To\Python\python.exe venv
Note
If Windows cannot find virtualenv.exe, see Install virtualenv. You can either add the executable’s home directory to your PATH variable, or just include the full path in your command line. If you aren’t sure where python.exe is installed, see Where’s My Python?.
Activate the Environment¶
Now that we have a virtual environment, we need to activate it.
After you activate the environment, your command prompt will be modified to reflect the change.
Add Libraries and Create a requirements.txt File¶
After you activate the virtual environment, you can add packages to it using pip. You can also create a description of your dependencies using pip.
The following command creates a file called requirements.txt that enumerates the installed packages.
pip freeze > requirements.txt
This file can then be used by collaborators to update virtual environments using the following command.
pip install -r requirements.txt
Deactivate the Environment¶
To return to normal system settings, use the deactivate command.
After you issue this command, you’ll notice that the command prompt returns to normal.
Hello Guys, How are you all? Hope You all Are Fine. Today I am trying to use virtualenv for my project but I am facing following error ‘virtualenv’ is not recognized as an internal or external command, operable program or batch file in python. So Here I am Explain to you all the possible solutions here. Without
wasting your time, Let’s start This Article to Solve This Error. I am trying to use virtualenv for my project but I am facing following error.
How To Solve ‘virtualenv’ is not recognized as an internal or external command, operable program or batch file Error ?
- How To Solve 'virtualenv' is not recognized as an internal or
external command, operable program or batch file Error ?
To Solve 'virtualenv' is not recognized as an internal or external command, operable program or batch file Error 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 Second solution is First of all open project folder where you want to use virtualenv. Now run this command on command prompt python -m virtualenv after running this command: run .\scripts\activate now you can see this type of line on cmd-prompt (django) C:\Users\ssc\Desktop\MyProject> Then main folder name before the source path. now you can install any modules for your project that belongs to that main folder only.
- 'virtualenv' is not recognized as an internal or external command, operable program or batch file
To Solve 'virtualenv' is not recognized as an internal or external command, operable program or batch file Error 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 Second solution is First of all open project folder where you want to use virtualenv. Now run this command on command prompt python -m virtualenv after running this command: run .\scripts\activate now you can see this type of line on cmd-prompt (django) C:\Users\ssc\Desktop\MyProject> Then main folder name before the source path. now you can install any modules for your project that belongs to that main folder only.
Solution 1: reinstall virtualenv
You just need to reinstall virtualenv. First of all you need to uninstall virtualenv with this command.
pip uninstall virtualenvThen just reinstall with this command.
pip install virtualenvSolution 2: Follow this step
Just follow this step to resolve this error.
- First of all open project folder where you want to use virtualenv.
- Now run this command on command prompt python -m virtualenv
- after running this command: run .\scripts\activate now you can see this type of line on cmd-prompt (django) C:\Users\ssc\Desktop\MyProject>
- Then main folder name before the source path. now you can install any modules for your project that belongs to that main folder only.
Summary
It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?
Also, Read
- _tkinter.TclError: no display name and no $DISPLAY environment variable