3

I have a simple script in python 3. I want to run with nodemon so that it can start automatically when the file changes. On nodemon npm, I have this code : nodemon --exec "python -v" ./app.py. The issue is that python version 3 is not enforced.

my python file looks like this:

#!/usr/bin/env python3
print "hello world!"

This code is working perfectly, this means Python 3 is not enforced.

How can I use nodemon and make sure it use Python 3 instead of 2?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
dmx
  • 1,862
  • 3
  • 26
  • 48
  • 1
    The "shebang" is only used when you do e.g. `./app.py` to run the script directly, that's how the shell chooses the executable. If you do `python ./app.py`, it uses the executable *you specifically asked for*. – jonrsharpe Nov 26 '20 at 11:19

2 Answers2

8

You can just use this:

nodemon --exec python3 hello.py

I found the answer here, it works well for me.

janw
  • 8,758
  • 11
  • 40
  • 62
  • 2
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/27788902) – Ivan Aracki Dec 07 '20 at 14:10
  • 1
    @IvanAracki Thanks for rectifying, it's my first time to answer question, i will answer according to your suggestions and community rules for the next time. – 仰望牛奶路 Dec 08 '20 at 05:17
1

I found a better solution: I just install reload and run reload ./myscript.py. Voilà

dmx
  • 1,862
  • 3
  • 26
  • 48