Py2exe: Embed static files in exe file itself and access them

前端 未结 3 951
名媛妹妹
名媛妹妹 2020-12-06 06:34

I found a solution to add files in library.zip via: Extend py2exe to copy files to the zipfile where pkg_resources can load them.

I can access to my file when library

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 06:59

    Thank you but I found the solution

    my_data = pkg_resources.resource_stream("__main__",sys.executable) # get lib.zip file
    zip = zipfile.ZipFile(my_data)
    data = zip.read("foo/media/doc.pdf") # get my data on lib.zip
    file = open(output_name, 'wb')
    file.write(data) # write it on a file
    file.close()
    

    Best Regards

提交回复
热议问题