How to package a Python command line app?

Loris Bennett loris.bennett at fu-berlin.de
Thu Dec 9 03:16:50 EST 2021


Hi Manfred,

Manfred Lotz <ml_news at posteo.de> writes:

> Hi Loris,
>
> On Wed, 08 Dec 2021 15:38:48 +0100
> "Loris Bennett" <loris.bennett at fu-berlin.de> wrote:
>
>> Hi Manfred,
>> 
>> Manfred Lotz <ml_news at posteo.de> writes:
>> 
>> > The are many possibilities to package a Python app, and I have to
>> > admit I am pretty confused.
>> >
>> > Here is what I have:
>> >
>> > A Python command line app which requires some packages which are
>> > not in the standard library.
>> >
>> > I am on Linux and like to have an executable (perhaps a zip file
>> > with a shebang; whatever) which runs on different Linux systems.
>> >
>> > Different mean
>> > - perhaps different glibc versions
>> > - perhaps different Python versions
>> >
>> > In my specific case this is: 
>> > - RedHat 8.4 with Python 3.6.8
>> > - Ubuntu 20.04 LTS with Python 3.8.10 
>> > - and finally Fedora 33 with Python 3.9.9
>> >
>> >
>> > Is this possible to do? If yes which tool would I use for this?  
>> 
>> I use poetry[1] on CentOS 7 to handle all the dependencies and create
>> a wheel which I then install to a custom directory with pip3.
>> 
>> You would checkout the repository with your code on the target system,
>> start a poetry shell using the Python version required, and then build
>> the wheel.  From outside the poetry shell you can set PYTHONUSERBASE
>> and then install with pip3.  You then just need to set PYTHONPATH
>> appropriately where ever you want to use your software.
>> 
>
> In my case it could happen that I do not have access to the target
> system but wants to handover the Python app to somebody else. This
> person wants just to run it.

For what ever reasons, there does not seem to be much focus on this kind
of deployment for Python.  Similar to the way things are with Perl, the
assumption seems to be that you have a working environment and install
any dependencies needed to get the program you have been given working.

I have never used it, but you might want to look at something like
pyinstaller 

  https://pyinstaller.readthedocs.io 

However, it looks as if it is aimed towards bundling a single script.  I
don't know how it would work if you have a more complex program
consisting of a number of modules.

>> Different Python versions shouldn't be a problem.  If some module
>> depends on a specific glibc version, then you might end up in standard
>> dependency-hell territory, but you can pin module versions of
>> dependencies in poetry, and you could also possibly use different
>> branches within your repository to handle that.
>> 
>
> I try to avoid using modules which depeng on specific glibc. 

So would I, but you mentioned it above in your definition of
'different'. 

> Although, it seems that it doesn't really help for my use case I will
> play with poetry to get a better understanding of its capabilities.

You're right, poetry doesn't seem to address your main problem.
Nevertheless, it might be useful for developing your program before you
get to the question of how to distribute it

Cheers,

Loris

-- 
This signature is currently under construction.


More information about the Python-list mailing list