5

I am working in an environment which has no sudo and internet access, therefore it is very useful to have a self contained application package that can be deployed anywhere.

Having used Maven to package my java projects into executable jar files, this was very useful in my situation.

However, I'm trying to achieve the same with python, possibly packaging all required dependencies into a zip/egg/wheel file so that this can be executed in any environment so long as they have python binary installed.

I've tried using python setup.py bdist_egg, but this creates an egg file without my top level main.py and the modules that I'm using.

Would greatly appreciate any experience in such scenarios!

chaooder
  • 1,358
  • 1
  • 17
  • 37
  • 1
    Did you look something like https://medium.com/dreamcatcher-its-blog/making-an-stand-alone-executable-from-a-python-script-using-pyinstaller-d1df9170e263 ? Also for compilation you are much better off with Go, than python. – Evgeny Apr 26 '19 at 11:51
  • @EPo Thanks! This looks good, but the application is built and deployed using a shared Jenkins which I have no access to, hence it will be better if I can build it with the usual tools (e.g. python setup.py, zip, mvn, etc). As for Go, the team is not well trained yet to use it – chaooder Apr 26 '19 at 12:07
  • 1
    You can package your app as an egg or wheel but this doesn't solve dependencies. My best answer to this would be to zip the project with a virtualenv that have everything installed. However this is not portable as virtualenv are system dependent. I upvoted as I have no clue how to solve that myself – Diane M Apr 26 '19 at 12:24
  • "*`python setup.py bdist_egg`*" The more modern format is wheel: `python setup.py bdist_wheel`. "*but this creates an egg file without my top level \__main__.py*" perhaps you've created a wrong `setup.py`. See https://packaging.python.org/ – phd Apr 26 '19 at 13:14
  • As for executable, see https://stackoverflow.com/q/5458048/7976758 and https://stackoverflow.com/search?q=%5Bpython%5D+standalone+executable – phd Apr 26 '19 at 13:19
  • If you need a self-contained executable dist, `distutils` or `setuptools` are wrong tools for that; you need [Pyinstaller](https://www.pyinstaller.org/) or [cx_freeze](https://anthony-tuininga.github.io/cx_Freeze/). Check out [Freezing Your Code](https://docs.python-guide.org/shipping/freezing/) for an overview of freezing tools available. – hoefling Apr 27 '19 at 09:21

0 Answers0