Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Flask using python3 not python

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 start the app with FLASK_APP=app.py flask run. It uses python2.7 to execute, I would like it to use python3.6.

Also tried adding #!flask/bin/python3 to app.py, but it did not have an effect.

like image 558
Money_Badger Avatar asked Mar 13 '18 11:03

Money_Badger


1 Answers

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

like image 108
Jonathan R Avatar answered Nov 02 '22 05:11

Jonathan R