On a project I'm involved with, we package our python product using compileall.compile_dir on an Ubuntu 14.04 (using Python 3.4). The directories of pyc files and such are bundled (tar.gz file) and distributed. The filenames are altered to remove the cpython-34 part of the filename.
We have a new test environment running Ubuntu 16.04 which has Python 3.5 and would like to run/test the code. When we unpack it and run it, we get an error :
$ ./configure
/usr/bin/python3: can't find '__main__' module in '/home/user/product/configure.pyz'
If I manually unpack the pyz file and attempt to run the python from the command line, after importing things, I get a message about it being a 3.4 binary. If I, instead, build the package on the 3.5 machine, I can totally run it on the 3.5 machine, but when I copy to 3.4, I get the same error.
Question is... what do I need to do to run/test it? Ideas I've had... running 3.5 in some sort of 3.4 compatibility mode. Install 3.4 (probably from source because I can't find a 3.4 package for Ubuntu 16.04). Maybe adjust some 3.5 config settings? Maybe provide a new setting when packaging to allow 3.4 and 3.5 to work? I assume I've missed some ideas, but I don't want to ask about what I think the solution is, I would like to know what the solution is.
Having googled and found a bunch of SO issues relating to pyc files, I know that the 3.4 files are not compatible, but are there ways to use it?
As you've mentioned, complied CPython files are not necessarily compatible between different versions, and are platform dependent.
I can see 2 different approaches, and would suggest a solution for each:
Change the way you distribute the software
If you use something like a Python wheel to distribute the software (then your application will be installed on the client side as a Python package), you can build a universal wheel that is version/platform independent. The starting point of your application would be scripts installed by the distributed module (the standard way of distributing Python modules).
Or you might want to try bundling the application as a standalone executable using PyInstaller or cx_Freeze (or something like that). This way you don't rely on the Python version of the clients, not even if they have any version of Python installed at all. The application is a standalone executable that runs on the corresponding platform/architecture.
Install the same version of Python on the machine you want to run your application
This is getting much easier these days with the help of containers (like docker). Or you might prefer to build it from the source if you have issues with using docker. But using docker is an easy one:
The line that runs Python container might need more adjustments for your application/configuration, but generally that's good enough.