website/content/blog/systemdwithpythonenvs.md

32 lines
699 B
Markdown
Raw Permalink Normal View History

2020-01-15 21:51:49 -05:00
---
title: "Systemd with Python environments"
date: 2019-08-25T20:04:20-04:00
draft: false
2022-01-02 14:24:29 -05:00
tags: [ "Linux", "Python" ]
2023-01-05 14:04:45 -05:00
medium_enabled: true
2020-01-15 21:51:49 -05:00
---
It took me some time to realize why I couldn't start a project during startup. I then realized that it was because I was using a python virtual environment and didn't tell systemd about it.
Here's how you can do so...
```yaml
[Unit]
Description=Start Service
# After=network.target # If you want a python webserver...
[Service]
Type=Simple
User=brandon
WorkingDirectory=/home/brandon/Development
ExecStart=/bin/sh -c ". /home/brandon/Development/pythonenv/bin/activate; /home/brandon/Development/start"
[Install]
WantedBy=multi-user.target
```