Run Flask using python3 not python

前端 未结 2 1348
隐瞒了意图╮
隐瞒了意图╮ 2021-01-02 16:42

How can you run Flask app which uses a specific version of python?

On my env \"python\" = python2.7 and \"python3\" = python3.6. I have installed Flask using pip3. I

相关标签:
2条回答
  • 2021-01-02 17:32

    There are several ways:

    1. Virtualenv lets you create isolated python environments with different versions (this is the way I would recommend)

    2. You can put #!/usr/bin/python3 on top of your python file (see here)

    3. Or you can start your script with python3 script.py

    4. As mentioned in the comments above you can also start your script inside a Docker container that hosts a python3 installation

    0 讨论(0)
  • 2021-01-02 17:32

    What I did was:

    1. which flask, to find flask binary executable path (in my case /home/myuser/.local/bin/flask

    2. edit /home/myuser/.local/bin/flask, changing the first line from #!/usr/bin/python to #!/usr/bin/python3

    In summary, making flask use python3, regardless of which shebang was specified in other scripts, since those scripts are not the entrypoint of execution, but flask is. I didn't have to change the shebang in any of my scripts, just the flask executable.

    0 讨论(0)
提交回复
热议问题