"">"">
Ad

Can't Import Package "No Module Named "

- 1 answer

I am currently using Flask/Blueprint to make my simple app more modular.

My directories look like this:

Jobscraperapp/
    application.py
    modules/
        __init__.py
        jobscraper.py

In application.py:

from flask import Flask
import modules.jobscraper

app = Flask(__name__)

app.register_blueprint(jobscraper)

I exported the pythonpath for the modules package from the jobscraperapp directory with the following code:

export PYTHONPATH="$PYTHONPATH:/modules"

but it always gives me an error that looks similar to:

No module named module
No module named module.jobscraper

etc.

What am I doing wrong here? Thanks!

Ad

Answer

You're adding /modules to PYTHONPATH, which is the root level directory modules; I think you intended either:

export PYTHONPATH="$PYTHONPATH:./modules"

or

export PYTHONPATH="$PYTHONPATH:modules"

Alternatively, you can add the full path to Jobscraperapp/modules:

export PYTHONPATH="$PYTHONPATH:/absolute/path/to/Jobscraperapp/modules"
Ad
source: stackoverflow.com
Ad