On 9/16/2023 7:57 PM, Rimu Atkinson via Python-list wrote:
It is nothing bad about using virtual environments but also not about
not using them. In my own work I haven't see a use case where I needed
them. And I expect that some day I'll encounter a use case for it. This
here is not about pro and cons of virtual environments.
You are in a use case where you need them, right now :) When you
understand the benefits of virtual environments you will understand what
I meant by that.
Please explain how the two problems I explained are influenced by not
using virtual environments.
The first problem can be avoided because virtual environments can use a
different version of python than the system one. If you need an earlier
version of python then you can use it instead.
I have multiple versions of Python on both Windows and Linux machines.
I don't have to use the system version. On Windows the "py" launcher
can launch any Python version on your system.
The second problem can be avoided because virtual environments exist in
a part of the file system that you have write access to, so you don't
need to use sudo to install packages. Your main user account does not
have write access to /usr/bin.
And therefore on Linux pip will install packages as --user even if the
option isn't specified. On Windows, one would just use --user routinely.
Also when a virtual environment is activated the path to it's packages
is a part of that environment so your code will always be able to import
the packages you want.
Whenever a version of Python is launched its system path is set up so
that its own packages are used. The one thing that can cause problems
is programs in the Python Scripts directory, which may not be on the
path for a particular version of Python. A virtual environment will
take case of that, but I almost never run scripts in that directory so
it's not an issue for me.
I think there are situations where a venv is useful, but not because of
the points you have asserted here. For myself, I find that after a
while, I tend to forget what I set up the various venvs for, and what
state they are in. So I have stopped using them. I just put up with
having more packages in /site-packages than a particular applications
needs. If I want to, say, work on code in a git clone's directory tree,
I launch Python using a batch file that sets the PYTHONPATH to point there.
It's much easier to understand if you try it for yourself. Google has
many excellent resources, here is one
https://www.freecodecamp.org/news/how-to-setup-virtual-environments-in-python/
Best of luck :)
R
--
https://mail.python.org/mailman/listinfo/python-list