For continous integration purposes, I am using the following builtin py3.6 venv command (not to be confused with virtualenv) (see pep 405).
python -m venv --system-site-packages --without-pip <ENVNAME>
I have found it to work great and I am getting an environment instantly.
BUT, .... venv produces a pyvenv.cfg file that looks like that:
home = absolute/path/to/prefix/of/interpreter/which/ran/venv
include-system-site-packages = true
version = <interpreter python version>
This file contains very crucial home key which refers to the original base python that this venv was created from. Very important to say that an invalid home key crashes python process which does not find its libraries in the base interpreter.
Now I want to deploy this "tested green" venv + its base python to the production machine. I don't want to rebuild it on the production system but just copying it to there.
Needless to say that the home absolute path created on the CI tool is not valid on the production machine, so I need to edit pyvenv.cfg file home key and everything is working like a charm.
This file manipulation is a step I really would like to avoid, as I would like to produce an artifact that just need to copied, activated and called (the standard way).
I tried to put %xyz%, $xyz and even configParser %(xyz)s on the original file but these do not resolve. I also tried to use a relative path there, but the path is relative to the working directory and I don't want to force the production system to call my artifact from a pinned working directory.
Is there a solution, other than the ugly pyvenv.cfg manipulation?
In windows:
Add the following code to activate.bat to dynamically generate pyvenv.cfg before each run.
type %CMDER_ROOT%\vendor\python3\p3\scripts\pyvenv_tmp.cfg | powershell -Command "$input | ForEach-Object { $_ -replace \"CMDER_ROOT\", \"%CMDER_ROOT%\" }" > %CMDER_ROOT%\vendor\python3\p3\pyvenv.cfg
pyvenv_tmp.cfg data:
home = CMDER_ROOT\vendor\python3
implementation = CPython
version_info = 3.10.4.final.0
virtualenv = 20.14.0
include-system-site-packages = false
base-prefix = CMDER_ROOT\vendor\python3
base-exec-prefix = CMDER_ROOT\vendor\python3
base-executable = CMDER_ROOT\vendor\python3\python3.exe
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With