A Python virtual environment is an environment isolated from your system, which allows you to run packages for a project separately from your system’s packages, so that you only use the packages that will be useful in your project.
In this mini-tutorial, we will learn more about Python virtual environments, how they work, and most importantly how to create and configure a virtual environment.
Normally Python programs use all the packages and modules that are installed in your system, even if only a few of them are used by the program; the logic of virtual environments is to limit the use of packages to those that are used in the Python program.
Norton Secure VPN 2023 for up to 5 Devices | |
19,99 $ |
In Python, there are several modules for creating virtual environments, the most well known of which are: virtualenv, Pipenv, Conda, venv which is usually delivered with Python. In this tutorial we will use venv, but any of these modules will do.
The following tools are essential for the rest of the tutorial:
Let’s move on to the most important part of the tutorial.
The creation of a virtual environment depends on the operating system you are using; To create a Python virtual environment with the venv module, 03 cases have to be taken into account
In this case, you just have to :
If you are using Linux as your operating system, after opening your command prompt and moving to the directory where you want to create the virtual environment, simply type the command: “python -m venv environment_name”.
Python3 as the current version of Python is version 3.
Creating virtual environments is all well and good, but in order to use them, you need to activate them. What do you need to do to activate a Python virtual environment?
As you may have guessed, activating a virtual environment also depends on the operating system used:
– On Windows, simply enter the following command in the “Scripts” child directory where your virtual environment is located: “activate.bat”
On the other hand, if you are on Linux, enter this command “activate” in the child directory
To do this, go to the root of your virtual environment and type the command “deactivate”.
You now know how to create and configure a Python virtual environment with the venv module.
Find out :
The Windows 11 update error can occur for several reasons, such as corrupted files, connectivity issues, or conflicts with third-party…
The "You don’t currently have permission to access this folder" error often appears when you try to access a folder…
When developing Flutter applications, it's common to encounter errors related to SDK version compatibility. One of these common errors is…
During the installation of Windows, you may encounter an error indicating that the selected disk is not compatible with the…
The error "Windows could not start the Windows Update service on the local computer" occurs when the operating system fails…
The Windows Update Service is essential for keeping your system up to date with the latest security and performance improvements.…