How to make Venv Python
Create a virtual environment in Python with an example: learn how to install & use venv for app development.
Creating a Virtual Environment in Python
Python virtual environments are used to create isolated development environments, allowing you to work on multiple projects without having to worry about dependency conflicts. A virtual environment, usually referred to as a ‘venv’, is essentially a folder that stores all the necessary executables, libraries, and files needed for a Python project. By using a virtual environment, you can ensure that all the packages installed for a particular project will not affect other projects on the same system.
Creating a virtual environment in Python is easy and can be done in a few simple steps. To create a virtual environment, you must first install the virtualenv
package using the command line. To do this, open up the command line interface (CLI) and enter the following command:
pip install virtualenv
This will install the virtualenv package, which will allow you to create virtual environments. Once the package has been installed, you can create a virtual environment by navigating to the directory where you want to store the venv and executing the following command:
virtualenv venv
This will create a directory called ‘venv’ in the current directory. In order to activate the virtual environment, you must enter the following command:
source venv/bin/activate
This will activate the virtual environment, and any packages you install while the environment is active will be stored in the venv folder. To deactivate the virtual environment, simply enter the following command:
deactivate
By using a virtual environment, you can ensure that all the packages installed for a particular project will not affect other projects on the same system. This is especially useful for projects that require multiple versions of the same package, or packages that have conflicting dependencies. By creating separate virtual environments, you can keep all of your projects isolated and ensure that they will run without any issues.