
On 2025-09-30 00:15:09 +0900 (+0900), Stephen J. Turnbull wrote:
Jeremy Stanley writes:
Note that "activating" a venv is typically not necessary (I never do it), you just have to make sure to type the full path to executables in the bin directory of the venv when running them, or add that directory to PATH in your shell environment.
I don't recommend the latter to folks who aren't experienced with Python. It can be confusing if you get a different Python from the one you expect due to upgrades/installations of other Python versions. Typing full paths or creating shell aliases/functions containing the full path is safe.
Yes, I should have included the caveat that adding a venv's bin/
directory to your PATH should only be for temporary measure or e.g.
if you have a dedicated account you want to log into specifically
for running those commands. This is part of what the activate script
in a venv does too, FWIW, it just gets undone again by the
deactivate command if/when you remember to run it later.
While understanding executable search order helps avoid accidentally shadowing other commands like your Python interpreter executable (append vs prepend), obviously altering your shell's PATH should not be done unless you fully comprehend the risks, which is why I suggested using the full path to the executable as the first recommendation.
A middle ground I take between those two is to add ~/bin to my PATH and then populate it with symlinks to executables in various venvs that contain my Python-based tools. This gives me the flexibility to only include the specific executables I want in my command search while omitting the rest.
Jeremy Stanley