Mar-13-2025, 02:09 AM
(This post was last modified: Mar-13-2025, 12:35 PM by bottomfeeder.)
I have a library installed in a venv which adds an .exe in the venv/Scripts/ folder. My Python script can find this .exe without explicitly activating the venv first, if I pass the script to venv/Scripts/python.exe (actually, by putting venv/Scripts/python.exe in the shebang line and using the Windows Python Launcher).
(sys.executable returns C:\path\to\venv\Scripts\python.exe in both accounts and permissions on the .exe make it accessible to both accounts. As a hack I am adding os.environ["PATH"] = f"{os.environ['PATH']};{os.path.dirname(sys.executable)}")
#!C:\path\to\venv\Scripts\python.exe import subprocess subprocess.run(["library.exe"]) # library.exe is located at C:\path\to\venv\Scripts\library.exeThis works without having to run activate first, I can just double-click on the script. However, if I run the script in a different user account, then it no longer works:
File "...\Python310\lib\subprocess.py", line 501, in run with Popen(*popenargs, **kwargs) as process: File "...\Python310\lib\subprocess.py", line 966, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "...\Python310\lib\subprocess.py", line 1435, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, FileNotFoundError: [WinError 2] The system cannot find the file specifiedOther aspects of the venv seem to work fine in this account (can use installed libraries). How do I make this work for all accounts?
(sys.executable returns C:\path\to\venv\Scripts\python.exe in both accounts and permissions on the .exe make it accessible to both accounts. As a hack I am adding os.environ["PATH"] = f"{os.environ['PATH']};{os.path.dirname(sys.executable)}")