Mailing List Archive

portable venv
Hi All,
I tried to compose a protable virtualEnvironment using Python. I aready found a solution which already works but still not stable.
So by creating venv in conventional way, I additionally copy the Python executable and related dlls, zip file, ._pth file to the root of venv folder.
The weak point of this solution is the pyvenv.cfg file and the value of the home variable!
It can accept both absolute or relative paths, it is fine and good as it is. Using this solution (copiing Python executable and other files) and changing home path to .\venv(as relative) I am able to fetch packages by using pip install.
But not all the packages! Eg pyinstaller changes the scope of calling Python.exe thatswhy not possible to fetch it. (Not found: .\venv\python.exe)

I assume during parsing of home path inside pyenv.cfg by converting it to absolute path(if a relative path was given) behind the scene, I and anybody else would have a fully functionally portable virtualenv solution!
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/3ODJAFXANFOTC5JB7TWEW45U46JHYI5U/
Code of Conduct: http://python.org/psf/codeofconduct/
Re: portable venv [ In reply to ]
On Tue, Nov 16, 2021 at 8:08 AM Tamás Ozsváth <tozsvath75@gmail.com> wrote:

> Hi All,
> I tried to compose a protable virtualEnvironment using Python. I aready
> found a solution which already works but still not stable.
> So by creating venv in conventional way, I additionally copy the Python
> executable and related dlls, zip file, ._pth file to the root of venv
> folder.
> The weak point of this solution is the pyvenv.cfg file and the value of
> the home variable!
> It can accept both absolute or relative paths, it is fine and good as it
> is. Using this solution (copiing Python executable and other files) and
> changing home path to .\venv(as relative) I am able to fetch packages by
> using pip install.
> But not all the packages! Eg pyinstaller changes the scope of calling
> Python.exe thatswhy not possible to fetch it. (Not found:
> .\venv\python.exe)
>
> I assume during parsing of home path inside pyenv.cfg by converting it to
> absolute path(if a relative path was given) behind the scene, I and anybody
> else would have a fully functionally portable virtualenv solution!
>

Do note that virtual environments do not work the same on all platforms.
For instance, on OSs that support symlinks (by default), the venv is not
self-contained by copying binaries in order to make their creation faster.
Virtual environments are also specifically designed and meant to be cheap
and disposable rather than relocatable/reusable in multiple situations.

If you want to make moving environments easier, then I would look at PEP
582: https://www.python.org/dev/peps/pep-0582/ .