Let's briefly turn our attention to the alternative ways that we can execute a Python script. As we will learn, choosing the appropriate method is all based around how and from where you intend to start your script and whether your code requires elevated permissions.
The most common way of running a Python script is from within its virtual environment and with the permissions of the currently logged in user. However, there will be scenarios where we need to run a script as the root user or from outside an activated virtual environment.
Here are the ways we will explore:
- Using sudo with virtual environments
- Executing Python scripts outside of their virtual environments
- Running a Python script at boot
Let's start by learning how to run a Python script with root user permissions.