0

I have the following setup:

animals
 - __init__.py
 - main.py
 - pets.py
  * class Dog

If I do from pets import Dog from main.py, I get a linter warning on the latest versions of pylint, flake8, and bandit. Intellisense recommends I do from animals.pets import Dog from main.py but this gives me ModuleNotFoundError: No module named 'pets'.

At this point it is really just an annoyance since I can ignore the linter warnings but I would really like to get this fixed.

EDIT:

I have tried the following things from main.py

from .pets import Dog
from . import pets.Dog
import pets.Dog

and many more. Every single one gives me either a linter warning or throws an error.

Kai Arakawa
  • 193
  • 1
  • 1
  • 14
  • The directory `animals` is in needs to be on the pythonpath to be found. – Peter Wood Aug 03 '20 at 22:37
  • 1
    run your code via `python -m animals.main` and not `python animals/main.py` -- the latter [does things to sys.path that you don't expect](https://github.com/asottile/scratch/wiki/PythonPathSadness) – anthony sottile Aug 04 '20 at 02:55
  • if that's the case, this is a dupe target (I'm not 100% sure or I'd mark it myself): https://stackoverflow.com/q/45448182/812183 – anthony sottile Aug 04 '20 at 02:57
  • 1
    @AnthonySottile Thank you! This did help. I wasn't able to find that thread before for some reason. This has been a problem for a while now that I've been ignoring but I have looked it up many times. I'll mark it. – Kai Arakawa Aug 04 '20 at 18:02

0 Answers0