'Upgrade package from script using pip on Python Version > 3.8.10

I would like to upgrade a package each time the script is started. The solution proposed here:

pip.main(['install', '--upgrade', package]).

Is causing on Python 3.8.10 the following error message:

WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.

How can I fix this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source