0

When using my Atom with Python using Pygame, whenever my code has any sort of file loading in it(such as pygame.image.Load() or pygame.font.Font() or pygame.mixer.Sound()), it gives me this error: "FileNotFoundError: No such file or directory.". Even though the file exists and my directions are accurate. The only way I can get it to work is by using the full directory. (e.g. file/file/file/game/images/image) and that is not ideal since I plan on selling games in the future. However, this problem does not occur in other IDEs such as python IDLE, and Pycharm. I am currently using Pycharm but the startup is slow and I prefer to use Atom. Any help is appreciated. I am also willing to give any information you need. (Other than personal stuff obviously.)

Ink Shade
  • 19
  • 2
  • The file path hat to be relative to the working director. The working directory is not the directory of the python file. Try `import os` `os.chdir(os.path.dirname(os.path.abspath(__file__)))` – Rabbid76 Oct 25 '21 at 21:29
  • Thank you so much for the help, but, just curious. Why doesn't this happen with pycharm? – Ink Shade Oct 25 '21 at 22:10
  • Pycharm ensures that the working directory is always the same as the python file directory. But this is not the case in the "real" world. – Rabbid76 Oct 25 '21 at 22:13
  • Okay thanks! Your solution worked. – Ink Shade Oct 25 '21 at 23:04
  • Also, I'm just wondering how come other people who use Atom such as DaFluffyPotato don't have this problem? He also uses python, and he is on Windows too. – Ink Shade Oct 25 '21 at 23:18
  • On windows you have the same problem. The working director can be equal the file directory. It depends how you start the application. Stop yammering and start reading e.g. [Working directory](https://en.wikipedia.org/wiki/Working_directory). – Rabbid76 Oct 26 '21 at 07:20

0 Answers0