Ubuntu Struggling to run Python Script on Startup

Solution 1:

I have found a solution to the problem. I found out you can activate the virtual environment for the project and then start the program inside of the virtual environment.

In the project, the venv can by activated via [project_path]/venv/bin/python

Here are the changes for the solution:

[Unit]
Description=Python Internet Watcher
After=network-online.target

[Service]
WorkingDirectory=/home/connor/Documents/Pycharm
ExecStart=/home/connor/Documents/Pycharm/venv/bin/python internettracker.py start
Restart=always
RestartSec=15s
KillMode=process
TimeoutSec=infinity
User=connor
Group=connor

[Install]
WantedBy=multi-user.target

command-line python