pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

SyntaxError: Non-UTF-8 error when running python scripts on Mac

Open toprakfirat opened this issue 1 year ago • 3 comments

What's going wrong?

My project file:

module.exports = { apps: [

{
  name: 'asd',
  script: 'python3 asd.py',
  watch: true,
  cron_restart: '30 * * * *', 
  interpreter: "/Users/user/miniconda3/envs/asd/bin/python3"
},

], };

I am trying to run a python script but I get the following error:

19|getStre | SyntaxError: Non-UTF-8 code starting with '\xcf' in file /opt/homebrew/bin/bash on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 19|getStre | File "/opt/homebrew/bin/bash", line 1 19|getStre | SyntaxError: Non-UTF-8 code starting with '\xcf' in file /opt/homebrew/bin/bash on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 19|getStre | File "/opt/homebrew/bin/bash", line 1 19|getStre | SyntaxError: Non-UTF-8 code starting with '\xcf' in file /opt/homebrew/bin/bash on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 19|getStre | File "/opt/homebrew/bin/bash", line 1 19|getStre | SyntaxError: Non-UTF-8 code starting with '\xcf' in file /opt/homebrew/bin/bash on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 19|getStre | File "/opt/homebrew/bin/bash", line 1 19|getStre | SyntaxError: Non-UTF-8 code starting with '\xcf' in file /opt/homebrew/bin/bash on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 19|getStre | File "/opt/homebrew/bin/bash", line 1 19|getStre | SyntaxError: Non-UTF-8 code starting with '\xcf' in file /opt/homebrew/bin/bash on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 19|getStre | File "/opt/homebrew/bin/bash", line 1 19|getStre | SyntaxError: Non-UTF-8 code starting with '\xcf' in file /opt/homebrew/bin/bash on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 19|getStre | File "/opt/homebrew/bin/bash", line 1 19|getStre | SyntaxError: Non-UTF-8 code starting with '\xcf' in file /opt/homebrew/bin/bash on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

If I delete the interpreter parameter and just use the default one, or if I just run it as:

pm2 start asd.py, I get the error and the output for a couple times:

/Users/user/.pm2/logs/asd-error.log last 15 lines: 27|asd | SyntaxError: Non-UTF-8 code starting with '\xcf' in file /opt/homebrew/bin/bash on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 27|asd | File "/opt/homebrew/bin/bash", line 1 27|asd | SyntaxError: Non-UTF-8 code starting with '\xcf' in file /opt/homebrew/bin/bash on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 27|asd | File "/opt/homebrew/bin/bash", line 1 27|asd | SyntaxError: Non-UTF-8 code starting with '\xcf' in file /opt/homebrew/bin/bash on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 27|asd | File "/opt/homebrew/bin/bash", line 1 27|asd | SyntaxError: Non-UTF-8 code starting with '\xcf' in file /opt/homebrew/bin/bash on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 27|asd | File "/opt/homebrew/bin/bash", line 1 27|asd | SyntaxError: Non-UTF-8 code starting with '\xcf' in file /opt/homebrew/bin/bash on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 27|asd | File "/opt/homebrew/bin/bash", line 1 27|asd | SyntaxError: Non-UTF-8 code starting with '\xcf' in file /opt/homebrew/bin/bash on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 27|asd | File "/opt/homebrew/bin/bash", line 1 27|asd | SyntaxError: Non-UTF-8 code starting with '\xcf' in file /opt/homebrew/bin/bash on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details 27|asd | File "/opt/homebrew/bin/bash", line 1 27|asd | SyntaxError: Non-UTF-8 code starting with '\xcf' in file /opt/homebrew/bin/bash on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

/Users/user/.pm2/logs/asd-out.log last 15 lines: 27|asd | aaa 27|asd | aaa 27|asd | aaa 27|asd | aaa 27|asd | aaa 27|asd | aaa 27|asd | aaa 27|asd | aaa 27|asd | aaa 27|asd | aaa 27|asd | aaa 27|asd | aaa 27|asd | aaa 27|asd | aaa 27|asd | aaa

How could we reproduce this issue?

The python script is just print("helloworld")

Supporting information

Model Name: MacBook Pro Model Identifier: MacBookPro18,2 Chip: Apple M1 Max

# Run the following commands
$ pm2 report

--- Daemon logs -------------------------------------------- /Users/user/.pm2/pm2.log last 20 lines: PM2 | 2024-01-10T22:35:11: PM2 log: App [asd:27] starting in -fork mode- PM2 | 2024-01-10T22:35:11: PM2 log: App [asd:28] online PM2 | 2024-01-10T22:35:11: PM2 log: App [asd:27] online PM2 | 2024-01-10T22:35:11: PM2 log: App [asd:28] exited with code [0] via signal [SIGINT] PM2 | 2024-01-10T22:35:11: PM2 log: App [asd:28] starting in -fork mode- PM2 | 2024-01-10T22:35:11: PM2 log: App [asd:28] online PM2 | 2024-01-10T22:35:11: PM2 log: App [asd:27] exited with code [1] via signal [SIGINT] PM2 | 2024-01-10T22:35:11: PM2 log: App [asd:27] starting in -fork mode- PM2 | 2024-01-10T22:35:11: PM2 log: App [asd:27] online PM2 | 2024-01-10T22:35:11: PM2 log: App [asd:28] exited with code [0] via signal [SIGINT] PM2 | 2024-01-10T22:35:11: PM2 log: App [asd:28] starting in -fork mode- PM2 | 2024-01-10T22:35:11: PM2 log: App [asd:28] online PM2 | 2024-01-10T22:35:11: PM2 log: App [asd:27] exited with code [1] via signal [SIGINT] PM2 | 2024-01-10T22:35:11: PM2 log: App [asd:27] starting in -fork mode- PM2 | 2024-01-10T22:35:11: PM2 log: App [asd:27] online PM2 | 2024-01-10T22:35:11: PM2 log: App [asd:28] exited with code [0] via signal [SIGINT] PM2 | 2024-01-10T22:35:11: PM2 log: Script /Users/toprak/RASTLANTI/deploy/asd.py had too many unstable restarts (16). Stopped. "errored" PM2 | 2024-01-10T22:35:11: PM2 log: App [asd:27] exited with code [1] via signal [SIGINT] PM2 | 2024-01-10T22:35:11: PM2 log: Script /opt/homebrew/bin/bash had too many unstable restarts (16). Stopped. "errored" PM2 | 2024-01-10T22:35:11: PM2 error: Cancelling versioning data parsing

toprakfirat avatar Jan 10 '24 19:01 toprakfirat

Same here on AWS EC2 (Linux/Ubuntu) with '\xef' character and MacOS with '\xca'. Moreover, I'm trying with poetry, everything works well when running manually the script with poetry or python itself.

steph-lion avatar Jan 15 '24 13:01 steph-lion

Hello, have you found the solution? Can you share?

Thanks in advance!!

uayes avatar Feb 23 '24 07:02 uayes

I stumbled across a similar kind of error but my startup script was in bash. I think it should be { ..., script: 'asd.py', ... } i.e. without python

sid203 avatar Feb 23 '24 09:02 sid203