ModuleNotFoundError when running child package module

Question:

proj
|
|
|---flaskr
|    |---__init__.py
|
|    |---scripts
|        |---__init__.py
|        |---build_database.py

My flaskr.__init__.py looks like this

import os
import connexion
from flask_cors import CORS


def create_app(test_config=None):
...

When I run build_database.py in the project root folder with the following command

python3 -m flaskr.scripts.build_database

I get the following error

ModuleNotFoundError: No module named 'connexion'

But I have installed connexion using pip and when I run the whole Flask app with flask run it works fine.

Any ideas why I’m getting the ModuleNotFoundError when running the build_database module?

Asked By: diyun

||

Answers:

I would run python3 -mconnexion to make sure python3 has access to the module. I suspect flask and pip are running under a different python interpreter then python3.

Answered By: toppk
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.