I followed the python docs for creating a package, but for some reason one of the submodules is not being found. I've looked at other questions that address similar issues, but the solutions have not worked.
Package Structure
src/
board_game_framework/
__init__.py
board.py
cell.py
game.py
Since the only thing that needs to be exposed to the end user is game.py
, it imports board.py
, which imports cell.py
.
I'm able to build and pip install .
the package, but when I test it with a simple
>>> import board_game_framework
I get the following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/xxx/anaconda3/lib/python3.8/site-packages/board_game_framework/__init__.py", line 2, in <module>
from .board import Board
File "/Users/xxx/anaconda3/lib/python3.8/site-packages/board_game_framework/board.py", line 3, in <module>
from cell import Cell, CellValue, Position
ModuleNotFoundError: No module named 'cell'
I thought this was an issue with __init__.py
, but I've tried multiple different ways of importing the modules. I've settled on the following, but could still be wrong.
from .cell import Cell, CellValue, Position
from .board import Board
from .game import Game, GameAction, GameDifficulty, GameState
I've also tried the following without success.
import cell
from board_game_framework import cell
from board_game_framework.cell import cell
from . import cell
The fix did not require a change in __init__.py
. Changing all the imports within the actual code, which needed the full import path. For example
Example: board.py
import cell # causing error
import board_game_framework.cell # fix
I didn't think this would be the issue since I would have expected it to throw the error when game.py
import board.py
, instead of going all the way though to board.py
importing cell.py
.