vbuzze
vbuzze

Reputation: 940

Path not found when executing my python script from my cmd prompt

folders

I have a python script that uses classes from a file next to my main.py named 'src'. These classes use images from the file 'img' next to main.py as well.

I'm writting the path as follows :

"img/myImage.gif"

When I run it from my python shell it works fine but I just can't run it using the command prompt (path not found).

I tried

"/img/myImage.gif" and "./img/myImage.gif"

and also moving my 'img' file to src, and to main.py's parent file but it doesn't work..

I'm out of ideas.. any assistance would be appreciated, Thanks,

Upvotes: 0

Views: 423

Answers (1)

Arun G
Arun G

Reputation: 1688

This is what you need to do for you folder structure,

program
   main.py
   src
      __init__.py //empty py file
      classA
           __init__.py
           classA.py

      classB
           __init__.py
           classB.py

"../../img/myimage.gif"          // to use in classA.py file

More Explanation:

if your main.py is in

    src
       main.py
    img
       myimage.gif

use this

"../img/myimage.gif"

if your folder structure is (moving img inside src)

-src
    main.py
   -img
       myimage.gif

you need to use like below

"img/myimage.gif"

Upvotes: 1

Related Questions