35
Recommended way to run my scripts from a venv?
(feddit.org)
Welcome to the Python community on the programming.dev Lemmy instance!
Past
November 2023
October 2023
July 2023
August 2023
September 2023
Just in case this comment didn't make it explicitly clear, you can just invoke the python binary inside your venv directly and it will automatically locate all the libraries that are installed in your virtual environment.
To show how this works, you can look at the
sys.path
variable to see which paths python will search for modules when you run import statements. Try runningpython3 -c 'import sys; print(sys.path)'
using your system python, and you will only see system python library paths. Then, try running it again after replacingpython3
with the full path to thepython3
binary in your venv, and you will see an additional entry in the output with thelib
directory in your venv, which shows that python will also look there for modules when an import statement is executed.