-1

I have three python versions installed in my system:

  1. python3.5
  2. python3.6
  3. python3.8

I have created a flask app which is waterchain.py

and setup my .flaskenv as shown below:

FLASK_APP=waterchain.py
FLASK_ENV=production

Now when I do a flask run, I get this error:

ModuleNotFoundError: No module named 'pymongo'

This is because although I have installed all the modules in python3.6 by default flask run chooses to run it on latest python version that is python3.8. Now in order to run all those apps, I would have to reinstall all the pip dependencies for python3.8. When I do a py -3.6 waterchain.py everything runs smoothly. Can someone point me a way to change default python running version for my flask app?

Shivam Sahil
  • 4,055
  • 3
  • 31
  • 62
  • 1
    Does this answer your question? [Run Flask using python3 not python](https://stackoverflow.com/questions/49255283/run-flask-using-python3-not-python) – noslenkwah Aug 13 '20 at 12:57
  • "When I do a py -3.6 waterchain.py everything runs smoothly." -- doesn't that answer your question? – Ken Kinder Aug 13 '20 at 12:58

1 Answers1

0

The best way to do this and with any other python project is to use virtual environments, as with them you can install/uninstall packages and manage their versions easily, thus being also able to choose which version you'd actually like to use.

Here you have a link to the documentation of how to use virtual environments: https://docs.python.org/3/tutorial/venv.html

Also, I prefer using pipenv, if you'd like to look into it, here you can find how: https://pypi.org/project/pipenv/

And a video tutorial if you'd really want someone talking while explaining and having a feel of how it looks like: https://www.youtube.com/watch?v=N5vscPTWKOk

Basically, with virtual environments you're setting up python packages per project, so that you can use for example different python versions, or different versions of packages for different projects. It's an easy to learn thing and really useful.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
skywallkee
  • 41
  • 4