-1

So I made a basic python script and converted it into an exe. When I made the script into an exe I was so excited and wanted to send it to my uncle .I compressed the script and a few files and images into a zip and
sent it to my uncle .When he opened the exe it failed and he realised that the error could be because I saved the images on drive D:/, when he unzipped the zip file it didn't save on his D drive.

While the exe works my computer it doesn't work on his so I'm trying to find out how to make the images not drive specific.

  • rather than saving on D, save on current folder, using just the filename and not the full path, maybe that will sort the problem out? – Je Je Dec 29 '22 at 18:14
  • I used cx_Freeze to create the windows exe – Mielutu Nelutu Dec 29 '22 at 18:23
  • and when I try to do what Je Je says it writes FileNotFoundError: No such file or directory – Mielutu Nelutu Dec 29 '22 at 18:25
  • `import os` `os.chdir(os.path.dirname(os.path.abspath(__file__)))`. See [Could not open resource file, pygame error: "FileNotFoundError: No such file or directory."](https://stackoverflow.com/questions/58177145/could-not-open-resource-file-pygame-error-filenotfounderror-no-such-file-or) – Rabbid76 Dec 29 '22 at 18:29
  • I try to do what you said but it gives me this error: – Mielutu Nelutu Dec 29 '22 at 18:33
  • File "d:\space_invaders\code\code.py", line 22, in man = pygame.transform.scale(man, (80,80)) TypeError: argument 1 must be pygame.Surface, not None – Mielutu Nelutu Dec 29 '22 at 18:33
  • here is the code: – Mielutu Nelutu Dec 29 '22 at 18:34
  • man = os.chdir(os.path.dirname(os.path.abspath("stickman.png"))) man = pygame.transform.scale(man, (80,80)) man_loc = man.get_rect() man_loc.center = man_x,man_y ship = os.chdir(os.path.dirname(os.path.abspath("ship1.png"))) ship = pygame.transform.scale(ship, (120,80)) ship_loc = ship.get_rect() ship_loc.center = 200,50 ship1 = os.chdir(os.path.dirname(os.path.abspath("ship1.png"))) ship1 = pygame.transform.scale(ship1, (120,80)) ship1_loc = ship1.get_rect() ship1_loc.center = 320,50 – Mielutu Nelutu Dec 29 '22 at 18:34
  • ship2 = os.chdir(os.path.dirname(os.path.abspath("ship1.png"))) ship2 = pygame.transform.scale(ship2, (120,80)) ship2_loc = ship2.get_rect() ship2_loc.center = 440,50 – Mielutu Nelutu Dec 29 '22 at 18:35
  • I never told you to us it like that. Read [Could not open resource file, pygame error: "FileNotFoundError: No such file or directory."](https://stackoverflow.com/questions/58177145/could-not-open-resource-file-pygame-error-filenotfounderror-no-such-file-or). Just put `import os` and `os.chdir(os.path.dirname(os.path.abspath(__file__)))` at the begin of your code, but do not change anything else. – Rabbid76 Dec 29 '22 at 18:36
  • I did it what is next – Mielutu Nelutu Dec 29 '22 at 18:44
  • Now the " FileNotFoundError: No such file or directory" error should be gone. – Rabbid76 Dec 29 '22 at 18:45
  • When adding details, information or other update to your question whether requested or not, do not add this in comments. Always EDIT and update the original question. – moken Dec 30 '22 at 06:30

1 Answers1

0

#create directory like this

application folder name (folder)
        └── your application.exe

        └── imgs (folder)
                |__ image.png
                |__ image2.png

[![enter image description here][1]][1]

in script use file paths like this

image1_path = "imgs\image.png"

image2_path = "imgs\image2.png"

Thisal
  • 64
  • 4