I'm finally disentangled from Python 2, thank you everyone

Chris Green cl at isbd.net
Wed Dec 30 05:58:42 EST 2020


> Could I ask you to write up a post on what you did here? I've never used 
> cx-freeze but it sounds like a useful thing for keeping legacy stuff 
> functioning. A writeup from someone who's actually used it for that 
> would be welcome.
> 
Of course, here is what I wrote in my 'self help' Dokuwiki wiki about it. It refers
specifically to the OKI software I wanted to keep using but it should be fairly
easy to apply a similar process to other software.


    I asked on the Python newsgroup and the one suggestion that seemed feasible was to
    package the OKI software with all its dependencies on a system which still has Gtk2
    and Python 2 and then install the whole package on esprimo.

    After a bit of looking around at Snap, Appimage and such I found cx_freeze which is
    aimed specifically at Python.  The latest version doesn't support Python 2 but 5.1.1
    does, so this is how I've have done it....

      * Install xubuntu 18.04 on my old Revo system (has to be 64-bit), 18.04 is still in support. (has to be 64-bit simply because the final target is 64-bit)
      * Install cx_freeze 5.1.1 on Revo
      * Install the Oki software on Revo, check that it works, pulls in lots of libraries and packages.
      * Run 'cxfreeze /usr/libexec/okimfputl/scantool.py' (scantool.py is the utility I want to run on systems without Python 2)
      * Copy the resulting 'dist' directory to the target system, name isn't critical

    Then the fun starts.  There's quite a few more libraries and packages are required
    and the scan daemon needs to be runnable.  (The scan daemon was, fortunately, just
    a compiled program so ran 'as is' without issues)

    Files needed in /usr/libexec/okimfputl and /usr/libexec/okimfpdrv
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    There are a lot of hard coded references to /usr/libexec/okimfputl and
    /usr/libexec/okimfpdrv, it **might** be possible to change all these but
    I decided it would be less painful to use a couple of symbolic links
    to locations in /usr/local/libexec and put the required files in
    /usr/local/libexec/okimfputl and /usr/local/libexec/okimfpdrv.

    I discovered what files are needed in these directories by simply running
    scantool on the target and fixing each error as it arose.

    Other Python package and library files
    """""""""""""""""""""""""""""""""""""
    I have installed the "dist" created by cxfreeze in /usr/local/libexec/okicxfreeze. The executable to run is thus /usr/local/libexec/okicxfreeze/scantool.

    There are also a few .so libraries and Python packages needed, as above I
    just found these by running scantool and fixing each error as it appeared.
    The system library files are put in /usr/local/lib, you have to run ldconfig
    after each file is put there.  The Python packages (including the dreaded
    pyscand.so) have to be put in the working directory when scantool is run,
    so I have put them in /usr/local/libexec/okicxfreeze where the scantool
    executable is.


I hope the above is useful.  As I said it refers specifically to the scantool.py
that I needed for my Oki scanner but I think the description is general enough to
be useful.

The basic process is:-

    Find (or create) a system where the software you want to run works OK.

    Install cx-freeze 5.1.1 on that system and run 'cxfreeze <thing you want to run>'

    Check that the executable created by cxfreeze works on the system you built it on

    Copy the executable (and its 'dist' environment) to the target where you want to run it

    Try and run it on the target

    Iteratively work through the errors it throws up when you run it, in my case these were:-

        Missing .so system library files, copy them from the build system to somewhere
        they will be found on the target.  You could put them in a 'private to the
        package' directory and set LD_LIBRARY_PATH or do as I did and put them in
        a standard library location (and run ldconfig after adding each).

        Missing Python packages, in my case this included the dreaded pyscand.so, I
        just put them in the 'package' directory with the executable and in the
        script that calls the executable set the directory so they are found.

        Data files.  In my case these had locations which were hard coded into all
        the various scripts along with scantool.py.  I *could* have changed all the
        code before building but that would have been a bit messy and error prone
        and there was no guarantee that there weren't some addresses hard coded in
        the executable files and libraries so I just (as you can see above) set up
        the required directories and put the required files there.  In my case this
        was just three or four configuration files and four .png image files.

    Note: It seems that what cxfreeze does is to create the *Python* environment needed
    to run a program.  It assumes that standard system .so files will be available
    on the target (e.g. libc etc.).  It doesn't check to see if any 'non-standard'
    .so files are needed.  The ones I had to copy across were all specific Oki
    ones that came with the Oki utility software.  I'm not quite clear why there
    were (just two) Python package files that didn't get included - one was
    pyscand.so (maybe because it was a .so) the other was a .py though.


If anyone wants further information or clarification feel free to ask, here or
direct to my E-Mail if you want, though keeping it here makes sense so everyone
can benefit.

-- 
Chris Green
·


More information about the Python-list mailing list