PYTHONPATH not working for sudo on GNU/Linux (works for root)

后端 未结 6 2225
梦毁少年i
梦毁少年i 2020-12-01 18:04

EDIT: Works for root, sudo is the problem. Read below.

I have a directory with my own libraries, e.g. my Python libraries are located at /home/name/lib/py

6条回答
  •  隐瞒了意图╮
    2020-12-01 18:51

    Follow configuration helps me to run multiple python services in dedicated VENVs on one Centos host

    1. Export env variables to separate file, for example /etc/sysconfig/my-app
    2. Set EnvironmentFile option in service config

    see code below:

    -bash-4.2$ sudo vi /etc/sysconfig/my-app
    
    PATH=/usr/local/my-app/env/bin:$PATH
    LD_LIBRARY_PATH=/usr/local/my-app/env/lib:$LD_LIBRARY_PATH
    
    
    
    -bash-4.2$ sudo vi /etc/systemd/system/my-app.service
    
    [Unit]
    Description=my-app daemon
    After=network.target
    
    
    [Service]
    EnvironmentFile=/etc/sysconfig/my_app
    User=app_user
    Group=app_user
    Type=simple
    ExecStart=/usr/local/my-app/env/bin/python /usr/local/my-app/main.py
    Restart=on-failure
    RestartSec=5s
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    

提交回复
热议问题