1

I googled for my problem and it lead me here: Bundling data files with PyInstaller (--onefile)

So I added the accepted answer's code,

def resource_path(relative):
    return os.path.join(
        os.environ.get(
            "_MEIPASS2",
            os.path.abspath(".")
        ),
        relative
    )


# in development
>>> resource_path("app_icon.ico")
"/home/shish/src/my_app/app_icon.ico"

# in deployment
>>> resource_path("app_icon.ico")
"/tmp/_MEI34121/app_icon.ico"

But I still receive a cannot locate imageName error. With the exception that it lists the _MEIPASS folder.

Is there something I'm missing?

Let me know if more info is needed. As far as I'm concerned, pyinstaller is black magic, so I'm unsure what would be relevant info.

Community
  • 1
  • 1
Zack
  • 4,177
  • 8
  • 34
  • 52

1 Answers1

0

I was stuck in this step too. Then I read pyinstaller.py file and have somehow managed to solve it successfully. After you modify the source file by adding the resource_path() method (as you have done already), you have to do the following steps:

  1. Run:

    python utils\Makespec.py --onefile your_script_name.py 
    
  2. Next edit the your_script_name.spec file from your_script_name folder created from the first step. Add these lines( adjust for your image name)

    a.datas +=  [('relative path from pyinstaller folder','actual path to image file','DATA')]
    

    for example like this,

    a.datas += [('calvin.jpg','C:\\projects\\python\\calvin.jpg','DATA')] 
    

    Note: I was not able to make it work, when I put my images in a subfolder so I kept them in the pyinstaller folder itself.

  3. Then finally run this:

    python pyinstaller.py your_script_name\your_script_name.spec
    

    That is run pyinstaller with .spec file you edited in the second step.

Hope this helps clear all your doubts :)

coding_pleasures
  • 859
  • 1
  • 9
  • 19