How can I distribute a Python application into an empty environment?

83 views Asked by At

I have a python3 app that I have written I need to install on a production, linux, server. For various reasons, this linux installation is very barebones. It will not have any version of python. It will not have Docker or anything similar. I don't know why that is the case, but those are my requirements. How can I deploy my python app to this server so it will function.

I had a few ideas:

  • Create an binary with something like pyinstaller. I have heard, however, that this does not really work very well and can be flaky.
  • Package up python in my install package with instructions to install it. This is not great, as it is supposed to be a zero-install package (although this might be acceptable).
  • Could this be as simple as just creating a python virtual environment? It seems like that includes the python interpreter (venv/bin/python). Someone I work with told me that will not work and python still needs to be installed on host environment. Not sure why.

I am going to play with this last option and see if it works.

2

There are 2 answers

2
Luan Zeqiri On BEST ANSWER

You could compile the .py file to an .exe file with the nuitka compiler use pip install nuitka and then you can compile the .py with nuitka --onefile --disable-console main.py you can try to leave out the --disable-console if you need the console. The Nuitka compiler doesnt compile like Pyinstaller by just packing the python interpreter. Nuitka compiles using gcc meaning c code. The .exe is then not obfuscated but actually compiled.

Here is a proper youtube tutorial for Nuitka: https://www.youtube.com/watch?v=z2aHkuBCLN8

0
TimothyH On

Honestly at the end of the day, Python was created for use as an embedded language, if you can't have anything installed that should work, you would need to read the documentation for embedding. Otherwise there are various answers. The aforementioned embedding should "just work" at every use case. NOTE: You will need to ensure that all packages are available.