pythonpython-3.xpm2

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


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


Solution

  • For anyone who is facing similar issue. That is

    SyntaxError: unterminated string literal (detected at line 29)
    File "/usr/local/lib/node_modules/pm2/lib/ProcessContainerForkBun.js", line 29
    // Change some values to make node think that the user's application
    

    The key point here is the commented line which is actually a message.
    You have to try modifying the parameters in my case it was something like this
    Set interpreter as "none" and script to "/absolute/path/venv/bin/python main.py"
    It might be different parameter for you tho. (If anyone has more in detailed answer please feel free to edit my answer)