Menu

Virtual Environments

When you install Python it creates a directory something like:

c:\users\xxxxxx\appdata\local\programs\python\python37-32\lib\site-packages

This is a global directory and any packages placed in it will be available to all Python projects. It is populated with the pip, setuptools and wheels packages as they come with Python as standard.

If you install more packages (e.g. "pip install numpy") they will be added to the site-packages directory by default. In most cases this is fine and the packages can be used by any number of Python projects you create.

Sometimes, though, a package is updated and the release is not compatible with previous releases. If you have projects dependent on the old release but you have a new project wanting to use new features you cannot simply update the package in the global site-packages directory because existing projects will break. The answer is to use a virtual environment, a place where packages that are specific to a particular project are stored.

Python comes with a "venv" module to create a virtual environment and the following command is run in the project directory.

py -3 -m venv venv

The first "venv" is the module name and the second is the name of the directory to be created to hold the virtual environment. Another directory name could be used but "venv" seems to be quite common.

A local site-packages directory is created in the virtual environment and packages can be installed in there by activating the environment before issuing the "pip install" command. The packages are then available only to current project and will not interfere with other projects.

For the WebExKit we only need to install the Flask package and the small part of it that is used is hardly likely to change so a virtual environment is not absolutely necessary. I use one because I prefer to keep project matters within the boundary of the project but that is personal choice.

There is another explanation at https://flask.palletsprojects.com/en/1.1.x/installation/#virtual-environments. It may be worth a read.


Related

Wiki: Installation Guide

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.