0

I am using poetry There is a tree of my project:
https://i.stack.imgur.com/PSJfI.png

I have such paths in my code:

SPACESHIP_FRAMES = (
    'space_game/frames/rocket/rocket_frame_1.txt',
    'space_game/frames/rocket/rocket_frame_2.txt',
)

Everything is working when I run my programm both as poetry script: space-game = "space_game.game:main" and as simple python script.

But! When I try to run space-game after installation game as pip package I see:

FileNotFoundError: [Errno 2] No such file or directory: 'space_game/frames/rocket/rocket_frame_1.txt'

How should I modify path to txt or pyproject.toml?

I tried different ways to write paths to txt files but nothing helped.

  • Two things: ***1.*** https://python-poetry.org/docs/pyproject/#include-and-exclude -- ***2.*** https://stackoverflow.com/a/58941536 – sinoroc Mar 25 '22 at 10:37
  • @sinoroc but after installation needed files are in package directory. https://i.imgur.com/SRx0KbI.png – Artem Nechai Mar 25 '22 at 13:55
  • Good. So now, look at step 2: https://stackoverflow.com/a/58941536 – sinoroc Mar 25 '22 at 13:58
  • modified code. paths for needed files in code were hardcoded. now i use os path join and everything works – Artem Nechai Mar 25 '22 at 14:11
  • Using `os.path.join` is a bad idea. Using `pkgutil.get_data()` as recommended in the answer I linked twice is a much better idea. If it is not possible, the next best is to use `importlib.resources`. – sinoroc Mar 25 '22 at 15:04

0 Answers0