In the previous article, you have learned about the installation of Python on a Windows system. This tutorial will help you to create a virtual environment in a Python application on Windows systems.
Create a Virtual Environment in Python
A Python module venv is available by default in Python 3.3 and later versions. To create a virtual environment, cd to your project directory and run the following command to create a new virtual environment.
Creating the requirements.txt File (Optional)
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. Activate Python Virtual Environment on Windows Use the following command to create requirements.txt containing all the installed packages on your system. This file can be used by the other project collaborators to install or update Python modules on their system virtual environments using the following command.
Deactivate the Virtual Environment
You can close the virtual environment and return to normal system settings, by typing the deactivate command: After executing the above command, you’ll notice that the command prompt returns to normal.
Conclusion
This tutorial helped you to create a virtual environment for your Python application on the Windows system.