Utoxin
Utoxin

Reputation: 448

Can't get submodule to import properly in another app

I'm building a couple of Python libraries/apps. I'm still relatively new to Python, and I struggle a lot with the import system. I think I've got a good handle on it for intra-app/module imports, but I'm now trying to import modules from a library I'm building for public release into my other project, and I flat out can't get it to recognize submodules for import.

The library in question is https://github.com/utoxin/PyChance

And I'm trying to import the 'SimpleTable' class from pychance/data/simpletable_class.py. I've tried multiple different import statements, and even different organizations of the library including moving simpleable.py up to the top-level directory, and various import lines in the library's init.py files.

My IDE suggests

from pychance import SimpleTable

with my current setup, but then immediately says that it can't find a reference to that in init.py.

If I try things like

from pychance.data import SimpleTable

it doesn't recognize that 'data' exists.

I'm probably missing something basic, but I can't figure out what I'm doing wrong.

ERRATUM

The PyChance package contains the following source files:

pychance/__init__.py
pychance/pychance_class.py
pychance/data/__init__.py
pychance/data/simpletable_class.py
pychance/parsing/__init__.py
pychance/parsing/parser.py
pychance/utility/__init__.py
pychance/utility/singleton.py

Source of pychance/data/__init__.py:

from .simpletable_class import SimpleTable

Source of pychance/data/simpletable_class.py:

import random


class SimpleTable:
    ...


if __name__ == '__main__':
    ...

(*) source code is truncated.

Upvotes: 3

Views: 155

Answers (1)

Laurent LAPORTE
Laurent LAPORTE

Reputation: 23012

According to the packaging of PyChance, the 2 following imports are functionals:

from pychance.data.simpletable_class import SimpleTable
from pychance.data import SimpleTable

I encounter no issue with PyCharm.

You may have a problem with your IDE.

Upvotes: 1

Related Questions