Python virtual environment (venv)
Python venv Installing Packages
You can run pip by calling the python executable inside the venv folder.
# This installs 'wheel' specifically into that virtual environment
/opt/venv/bin/python -m pip install wheel
Python venv Running Scripts
you can run your Python script by pointing fully to the venv python executable.
/opt/venv/bin/python /path/to/your/script.py
When you run Python this way, it automatically looks for modules inside /opt/venv/lib/pythonX.X/site-packages. It is fully isolated from the system Python.
Python venv Example for Cron
If you wanted to run a script every day at 5 AM via Cron, you would write:
# Correct way (No activation needed)
0 5 * * * /opt/venv/bin/python /home/user/scripts/daily_task.py