Python Forum
How does venv update $PATH without activating on Windows?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How does venv update $PATH without activating on Windows?
#1
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).

#!C:\path\to\venv\Scripts\python.exe

import subprocess

subprocess.run(["library.exe"]) # library.exe is located at C:\path\to\venv\Scripts\library.exe
This 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 specified
Other 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)}")
Reply
#2
This seeks ffmpeg-normalize.exe in all available PATHs.
subprocess.run(["ffmpeg-normalize.exe", r"C:\path\to\audio.mp3")
AFIK the ffmepg tools are not installed via pip.

If you installed ffmpeg as a normal user, then it does not appear in the PATH of other Windows users accounts. If it's installed systemwide, you'll find it somewhere in C:\Program files.

Install ffmepg system-wide to make it accessible to all users. Maybe you need to add the path of the bin directory to your system-wide PATH variable. Usually a normal user is not able to run from other users installed software, because it is in their home directory, which access is prevented to other users.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
That's ffmpeg-normalize, not ffmpeg. It is a pip package. I'm not asking how to locate ffmpeg, I'm asking how to have python locate exes within a venv's Scripts/ directory (which is where ffmpeg-normalize.exe is located, but it could be any exe that has nothing to do with ffmpeg, ffmpeg-normalize was just the example I was working with).
Reply
#4
(Mar-13-2025, 12:27 PM)bottomfeeder Wrote: That's ffmpeg-normalize, not ffmpeg. It is a pip package. I'm not asking how to locate ffmpeg, I'm asking how to have python locate exes within a venv's Scripts/ directory (which is where ffmpeg-normalize.exe is located, but it could be any exe that has nothing to do with ffmpeg, ffmpeg-normalize was just the example I was working with).
You are making the wrong assumption.
Can't remember what you installed?!
The python package ffmpeg-normalize does not ship with executable files. It uses an existing ffmpeg installation, which is independent of Python.

https://pypi.org/project/ffmpeg-normalize/
Quote:
  • Install a recent version of ffmpeg
  • Run pip3 install ffmpeg-normalize
  • Run ffmpeg-normalize /path/to/your/file.mp4
  • Done! 🎧 (the file will be in a folder called normalized)

The raised exception from subprocess.run is clear. Python could not find the executable file in PATH.

The path to the exe file ffmpeg.exe is constructed by this function: https://github.com/slhck/ffmpeg-normaliz...ls.py#L147

If a different user has no access to ffmpeg.exe you get the Exception you've posted. Install ffmpeg systemwide or for each user in %localappdata%\Programs\ and append it to the User-PATH.

You can test it by yourself:
from shutil import which


if ffmpeg := which("ffmpeg"):
    print(ffmpeg)
else:
    print("ffmpeg.exe not found")
If ffmpeg.exe was not found, then ffmpeg-normalize could not work.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  JenkinsFile to create a Python venv NikitaMathur 2 1,585 Sep-23-2024, 11:33 AM
Last Post: NikitaMathur
  Troubleshooting Jupyter Notebook installation with Python using pip and a venv Drone4four 1 2,162 Jun-04-2024, 10:55 PM
Last Post: Drone4four
  my venv is not loading njoki 1 1,773 Mar-20-2024, 10:41 AM
Last Post: snippsat
  working directory if using windows path-variable chitarup 2 1,490 Nov-28-2023, 11:36 PM
Last Post: chitarup
  Python venv and PIP version issue JanOlvegg 2 3,401 Feb-22-2023, 02:22 AM
Last Post: JanOlvegg
  Visual Studio Code venv ibm_db error mesi1000 7 4,921 Nov-13-2022, 12:36 AM
Last Post: snippsat
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 3,171 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  pip and venv virtual environments soupworks 2 3,002 Dec-30-2020, 11:38 PM
Last Post: soupworks
Question Python + Google Sheet | Best way to update specific cells in a single Update()? Vokofe 1 3,992 Dec-16-2020, 05:26 AM
Last Post: Vokofe
  Not able to set up a virtual environment with venv mohanp06 7 20,207 Oct-27-2020, 12:18 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020