We have a problem making python code, that is used by a process hosted on a network drive, run on multiple machines. I thought virtualenv would be a good way to solve this problem, but the additional complication of sharing an installation makes this a challenge.
Setup:
Machine H:
- hosts network drive D
- doesn't execute anything
Machine A:
- has python installed
- has created the virtualenv on D
Machine B:
- may have python installed, but no additional packages
Drive D:
project/
|- SomeProcess.kjb
|- venv/
|- Scripts/
|- activate.bat
|- [...]
|- python_package/
|- entry_point.py
|- [...]
On drive D we have an installation of a process that is executed by different machines and, as part of the execution, calls some python code. Specifically this a Kettle job, but I don't think this matters. The point is that during the process it calls the python code by running
/D/project/venv/Scripts/activate.bat
python /D/project/python_package/entry_point.py
in a shell-like environment. The job itself is run by a program that must be installed and executed on the calling machine. This works IFF the calling machine is also the one that created the virtualenv on the drive. If another machine tries to run the process, it stops with errors related to not using the correct python installation such as:
Traceback (most recent call last):
File "D:\project\venv\lib\site.py", line 761, in <module>
main()
File "D:\project\venv\lib\site.py", line 738, in main
paths_in_sys = addsitepackages(paths_in_sys)
File "D:\project\venv\lib\site.py", line 271, in addsitepackages
addsitedir(sitedir, known_paths)
File "D:\project\venv\lib\site.py", line 202, in addsitedir
addpackage(sitedir, name, known_paths)
File "D:\project\venv\lib\site.py", line 170, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "D:\project\venv\lib\importlib\util.py", line 14, in <module>
from contextlib import contextmanager
ModuleNotFoundError: No module named 'contextlib'
The alternative of not using a virtualenv is not desirable as it requires the calling machines to have the required python packages installed globally.
A possible fix is to install a virtualenv for each calling machine and switching to the correct one on execution of the process. However we currently have no idea how to get the process to recognize the calling machine and select the right virtualenv.
Is this a problem that can be solved with virtualenvs? Maybe we should look into finding alternative workflows that don't have this problem.