Trying to figure out if there's a good way to inline a module into a Python script. I may just have to write my own tool for that.

Now thinking about syntax if I do write my own tool. It should probably trigger a syntax error so we don't end up with a missing module.

$include file.py

Then a relatively simple script can find all of those lines and replace them with the file contents.

Basically I'm trying to statically link Python scripts so I can distribute them without saying "first, install this module I wrote and that you'll only need for these specific scripts..."

Follow

@alexbuzzbee This is more or less how PyInstaller works, though I will say that you are probably way better off using normal packaging and having people either install your scripts with a system installer or pipx or something.

@pganssle PyInstaller bundles an interpreter and the standard library. I'm not looking to do any of that, just to be able to give someone a script and have them be able to run it with an existing Python installation.

@alexbuzzbee My understanding is there's a "compile everything into a single file" mode, which is what I was referring to.

Though again I sorta think "Here is a wheel install it with pipx then you can run it" or "install this thing in a virtual env and run it" is not that big a deal.

@pganssle My understanding of PyInstaller is that it takes your script, your modules, their dependencies, the standard library, and the Python interpreter, and packs them into a single executable. That's massive overkill for this project. My target userbase already has Python, or can easily install it. I don't want to make someone set up a virtualenv or really install something at all to run a utility script. Including just the module itself into the script is all I need or want to do.

Sign in to participate in the conversation
CleverLibre Social

CleverLibre Social is an inclusive social instance for open discussion, learning, and community.
All cultures welcome.
Hate speech and harassment strictly forbidden.