Wednesday, 17 October 2018

No module named 'src' when run from app.py

I've my project folder structure like below.

├── LICENSE.md
├── README.md
├── requirements.txt
└── src
    ├── app.py
    ├── common
    │   ├── database.py
    │   └── __init__.py
    ├── __init__.py
    ├── models
    │   ├── blog.py
    │   ├── __init__.py
    │   ├── post.py
    │   └── user.py
    ├── static
    │   ├── assets
    │   ├── css
    │   │   └── main.css
    │   └── js
    └── templates
        ├── base.html
        ├── login.html
        └── profile.html

And yeah, this is a flask project. The whole project used to work fine. Until it was required to have from src.models.user import User inside app.py.

All the python files inside models directory interact with each other with the same src.models.blah convention.

Every subdirectory has __init__.py file in it, there shouldn't be any problem. I don't know where the problem is coming from.


What I already tried:

I was looking for answers on #python channel on freenode. Someone suggested using a setup.py to make a package, taking this template as reference:

import setuptools

setuptools.setup(
    name="pkg",
    packages=setuptools.find_packages('src'),
    package_dir={'': 'src'},
    entry_points={
        'gui_scripts': [
            'main = pkg.main:main',
        ],
    },
    install_requires=[
        'pyqt5',
        'pyopengl',
    ],
)

But this didn't help much.



from No module named 'src' when run from app.py

No comments:

Post a Comment