[Python] How deploy python script with pm2 and virtual env using ecosystem.config.js

Discussão em 'Python' iniciado por Stack, Abril 10, 2025.

  1. Stack

    Stack Membro Participativo

    module.exports = {
    apps : [{
    name : "my_app",
    cwd : "/abosolute/path-to/my-app/",
    script : "main.py",
    cron_restart : "0 * * * *",
    interpreter: "/absolute/path-to/venv/bin/python",
    log_date_format: "DD-MM HH:mm:ss.SSS"
    }]
    }


    I get the following error

    0|my_app | 10-04 16:03:15.501: SyntaxError: unterminated string literal (detected at line 29)
    0|my_app | 10-04 16:03:15.527: File "/usr/local/lib/node_modules/pm2/lib/ProcessContainerForkBun.js", line 29
    0|my_app | 10-04 16:03:15.527: // Change some values to make node think that the user's application
    0|my_app | 10-04 16:03:15.528: ^
    0|my_app | 10-04 16:03:15.528: SyntaxError: unterminated string literal (detected at line 29)
    0|my_app | 10-04 16:03:15.557: File "/usr/local/lib/node_modules/pm2/lib/ProcessContainerForkBun.js", line 29
    0|my_app | 10-04 16:03:15.557: // Change some values to make node think that the user's application


    I'm able to run the script using cmd

    pm2 start main.py --interpreter=../venv/bin/python


    Also works in following 2 cases

    1. when I remove cwd and provide absolute path in script it works but I don't want that as it creates issues with python script reading files.
    2. When I remove interpreter it uses the default global interpreter and runs the script

    Node Version: v18.19.1 PM2 Version: 6.0.5 Python Version: 3.12.3

    Continue reading...

Compartilhe esta Página