Talendar / flappy-bird-gym

An OpenAI Gym environment for the Flappy Bird game
MIT License
111 stars 68 forks source link

human mode: No such file or directory #3

Open DougTrajano opened 3 years ago

DougTrajano commented 3 years ago

Hey buddy. Firstly, congratulations on this project.

So, I had an issue with the human mode haha 😄

https://github.com/Talendar/flappy-bird-gym/blob/d014428c187031bcd97ee7315f6141bdf590c119/README.md?plain=1#L77-L79

Logs

PS C:\Users\trajano> flappy_bird_gym
Traceback (most recent call last):
  File "c:\programdata\anaconda3\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\programdata\anaconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\ProgramData\Anaconda3\Scripts\flappy_bird_gym.exe\__main__.py", line 7, in <module>
  File "c:\programdata\anaconda3\lib\site-packages\flappy_bird_gym\cli.py", line 79, in main
    flappy_bird_gym.original_game.main()
  File "c:\programdata\anaconda3\lib\site-packages\flappy_bird_gym\original_game.py", line 70, in main
    pygame.image.load(ASSETS_DIR + '/sprites/0.png').convert_alpha(),
FileNotFoundError: No such file or directory.

System Information

chokychou commented 3 years ago

cd flappy_bird_gym/ It should then work.

DougTrajano commented 3 years ago

I install it using pip install flappy-bird-gym.

hbonnavaud commented 2 years ago

same problem

prabathbr commented 2 years ago

I am also getting the same issue with Human mode on Python 3.9.7 after installing with pip install flappy-bird-gym. Random agent method is working fine with flappy_bird_gym --mode random.

I found a temporary solution by changing directory to E:\Miniconda3\envs\tf2\Lib\site-packages [This should be according to your installation, it is different from my setup] and running pip install flappy-bird-gym for there. Alternatively one can add this folder to $PATH system variable and it should work too [I haven't tried]. Then the Human mode works perfectly. So the issue is with the relative path to the pypi installed package directoy.

The actual issue is in original_game.py by directly mentioning ASSETS_DIR variable as ASSETS_DIR = "./flappy_bird_gym/assets"

Permanent Solution:

Replace ASSETS_DIR = "./flappy_bird_gym/assets" on original_game.py with

import os
from pathlib import Path
_BASE_DIR = Path(os.path.dirname(os.path.realpath(__file__))).parent
ASSETS_DIR = str(_BASE_DIR / "flappy_bird_gym/assets")

Original Error:

C:\Windows\system32>flappy_bird_gym
Traceback (most recent call last):
  File "e:\Miniconda3\envs\tf2\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "e:\Miniconda3\envs\tf2\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "e:\Miniconda3\envs\tf2\Scripts\flappy_bird_gym.exe\__main__.py", line 7, in <module>
  File "e:\Miniconda3\envs\tf2\lib\site-packages\flappy_bird_gym\cli.py", line 79, in main
    flappy_bird_gym.original_game.main()
  File "e:\Miniconda3\envs\tf2\lib\site-packages\flappy_bird_gym\original_game.py", line 70, in main
    pygame.image.load(ASSETS_DIR + '/sprites/0.png').convert_alpha(),
FileNotFoundError: No file './flappy_bird_gym/assets/sprites/0.png' found in working directory 'C:\Windows\system32'.

Temporary Solution:

E:\>cd E:\Miniconda3\envs\tf2\Lib\site-packages
E:\Miniconda3\envs\tf2\Lib\site-packages>flappy_bird_gym
E:\Miniconda3\envs\tf2\Lib\site-packages>