-1

I need to deploy a python application to a machine where python is not installed, and cannot be installed in the traditional sense. I cannot use containerization technologies such as docker. The only guarantees about the target I have are

  • Glibc is present
  • Some linux kernel is present
  • gunzip/unzip/another archiving tool is present

In java world I would package into an archive entire development kit (since there's no runtime environment anymore), write a crude shell script that sets JAVA_HOME (development kit location), and adds all the dependencies to "classpath/modulepath" (what modules should be loaded at runtime). Such deployments are resilient, as they do not clash with what ever is in the system (there may be another java installation on the system) and they're self contained: they have everything that is needed to run the application.

Looking at python equivalent solutions I'm seeing virtual environments, but I fail to grasp how to build such equivalent environment for python as it keeps symlinking to my currently installed python version on the system, which I cannot provide as an archive. Is there an equivalent way to "download the SDK, set PYTHON_HOME, add loadable modules, run entrypoint" with virtual environments?

Dragas
  • 1,140
  • 13
  • 29
  • 3
    A Python virtual environment is really just a way to install dependencies in a localised directory instead of globally for all Python projects. You do need an already installed Python for that. You first need to find a portable Python executable, _then_ you may or may not use virtual env to install the actual Python program and its dependencies. – deceze Jul 28 '23 at 09:14
  • 2
    PyInstaller could potentially be what you could use ? It will package your dependencies and assets into executable that you can then copy to the host. How well pyinstaller works in practice - for that i can't say anything. – rasjani Jul 28 '23 at 09:35
  • 1
    https://stackoverflow.com/a/12059644/7976758 , https://stackoverflow.com/search?q=%5Bpython%5D+standalone+script – phd Jul 28 '23 at 11:14

1 Answers1

0

Because the question lacks information about the nature of the application, any answer is a bit shot in the dark. Please read xyproblem.info on the background of how to add more context to your question.

Docker is a popular solution for doing Python + native libraries + native executables in self-contained deployments.

Of course the downside is that the target machine needs to have Docker installed. Luckily, Docker (and its equivalents) are a standard tool in Linux world today.

If this is not an option and the only tool you have is gunzip then you simply just use gunzip and work it with shell scripting case by case basis. There is no generic solution to deploy applications across different Linuxes if they do not run compatible UNIX userland binaries and such. Note that containers where specifically created to solve this problem.

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
  • The question clearly specifies that it is a python application, and requires python. It imposed clear limits that it needs a full package that you can send over to any user which includes full runtime of python, and have that somehow deployed. It imposed another limitation that it must not depend on docker. This isn't an XY problem. This is a problem that is pretty common in application deployment where you do not or cannot know about the oddities of the target. See all the installers for windows applications: they set up the environment so application could run. – Dragas Jul 28 '23 at 09:31
  • 1
    Thank you Dragas. The question, for example, does not include information about the application itself: desktop application, self-hosted website, server application and *why* you would do this. Linux was variety of ways to install applications depending on the application use case. However if you can know nothing about the target and cannot set on the requirements on the user what they have, then you have already have answered to your own question and there is no silver bullet that can help you. Every – Mikko Ohtamaa Jul 28 '23 at 10:32
  • 1
    Linux distribution, like Windows, has its own distribution format and application installer. Just use one of these installer and package formats and you are fine. However due to historical reasons, Linux community is bunch of angry nerds who fail to come up any kind of standard Linux application distribution format that would work. Thus, treat every Linux distribution ass their own operating system and there is no "common" Linux. – Mikko Ohtamaa Jul 28 '23 at 10:34
  • 1
    Presence of glibc implies that there is a "common" linux environment. There is no difference between "server" or "desktop" linux environments. The question is "how to package python application in such a way that it is isolated from the environment". It does not matter whether it's a website, or a long running application. Does it really matter whether I'm targetting linux from scratch or centos or busybox? No the only difference between them is the version of libc packaged in them, which is what I outlined: I need glibc. I know the target will have it. I am not guaranteed about anything else. – Dragas Jul 28 '23 at 11:05
  • Because you are doing things unusual way, you will have unusual problems. It matters a lot because there is no target "Linux", but the target of different Linux distributions. Linux is the kernel, operating system is the distribution. So it matters a lot. If you want to do a "prepackaged binary, everything statically linked and included". it can be done, but no one, or not a lot of people are doing it. So it is going to be a challenge which you should try to avoid if possible. – Mikko Ohtamaa Jul 28 '23 at 11:07
  • 1
    The examples of packaging java application with its development kit or a windows installer which sets up the environment to run the application do just that. I gave them as references on what I can do for applications developed in other tools besides python. The java example in fact works on linux deployments very well. All you need to know whether to package musl dependent JDK or a glibc dependent JDK. – Dragas Jul 28 '23 at 11:10
  • The problem with Java example is that it requires Java run-time to be present and this needs to be obtained thru a separate installer, through a various ways for different Linux distributions. You ask there is no specific Python version to be present, so you are asking for a different starting point. – Mikko Ohtamaa Jul 28 '23 at 11:12
  • The starting point is that I package the installation myself and provide that as the final distributable package. The question is about how to build such package. The example itself shows that "I include entire JDK". – Dragas Jul 28 '23 at 11:14
  • Then the one way to go forward is "Include entire Docker" – Mikko Ohtamaa Jul 28 '23 at 11:16
  • But to just to highlight, I don't want to be an asshole here (which I properly am), but trying to be genuinely helpful and trying to understand this interesting issue. As I said, this is not what most people do, but let me dig up something that might helpful for you now you clarified that you can bundle stuff. – Mikko Ohtamaa Jul 28 '23 at 11:24
  • You should likely go PyOxidizer https://pyoxidizer.readthedocs.io/en/stable/pyoxidizer_distributing_linux.html - it "mostly" solves distribution problems or "mostly" , but it comes with a limited set of Linux distributions and you still might need external dependencies, especially if you do HTTPS/other such activities – Mikko Ohtamaa Jul 28 '23 at 11:32