On a CentOS 7 server, I have installed Python 3.6 via SCL. ( https://www.softwarecollections.org/en/scls/rhscl/rh-python36/)
I have this line in .bashrc to enable SCL's Python 3.6
source scl_source enable rh-python36
I have installed pipenv:
pip install --user pipenv
I run Python programs via the command line:
pipenv run python myprogram.py
All these work great. I have a Flask application that uses the user's pipenv. I am trying to create a systemd unit file to start/stop/reload the Flask web application. How can I get the sytemd unit file to use the user's pipenv installed via SCL's Python and pip?
I tried to execute the command line from root and I get this error:
[root@localhost ~]# source scl_source enable rh-python36
[root@localhost ~]# /home/user/.local/bin/pipenv run python /home/user/hello.py
Traceback (most recent call last):
File "/home/user/.local/bin/pipenv", line 7, in <module>
from pipenv import cli
ModuleNotFoundError: No module named 'pipenv'
However, I am able to execute the command via su -c by loading user's bash shell:
su -c 'bash -lc /home/user/.local/bin/pipenv run python hello.py' user
But this line seems awkward. What is a the correct line I could use in systemd unit file's ExecStart line? What environment variables should be included in order to use the user's pipenv?
Here's my working systemd unit file: