Pack python library to one file [closed]

只谈情不闲聊 提交于 2019-12-25 02:47:22

问题


I want to pack pure python library into one source python script. (not exe, app, etc. I need exactly lib.py file) Is it possible? Which tools are exist for this?


回答1:


Best is to pack all your python files into a zip: https://blogs.gnome.org/jamesh/2012/05/21/python-zip-files/

If you really want to, sure, it is possible to pack everything (including a zip I think) to a .py file, just write your custom importhook, store base64-encoded zip archive as a string in your since python source, a bit of hardcore magic here and there and voila, single python program,

Alternatively you could refactor all your dependencies and include these as classes for example in your source, but why bother?

Finally, there's no simple way to include compiled dependencies, i.e. those .so / .dylib / .dll files.

I don't think there is a tool out there that does exactly what you want, but I reckon pyinstaller/py2exe can be used to get pretty close, for example http://www.py2exe.org/old/ look for library.zip.



来源:https://stackoverflow.com/questions/23426211/pack-python-library-to-one-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!