Reputation: 9798
In virtual environment (created with poetry) I'm running a Python script regularly as current user via
poetry run ./script.py
or
.venv/bin/python3 script.py
From within this script I need to run another script with root
privileges, which boils down to running that script via sudo:
sudo .venv/bin/python3 other_script.py
or
ssh root@localhost /<path>/<to>/.venv/bin/python3 /<path>/<to>/other_script.py
(I probably could also setuid
the script but I'd prefer the ssh
-way since I need it anyway. Also installing the virtual environment for root
is not an option for me)
Running a script this way will create __pycache__
folders and .pyc
files owned by root and running python3 -B
or setting PYTHONDONTWRITEBYTECODE
will not create any bytecode files at all (which I'd also like to avoid).
On an abstract level - is there a nice way to run a Python3 script from an existing virtual environment owned by current user with root
privileges without having to fiddle with setuid
or missing pyc
files?
Can I somehow tell Python (or the current environment) to create pyc
files/folder with certain ownership or at a location owned by root
?
Upvotes: 1
Views: 104