How to make python auto-select right pyc file to execute?

74 Views Asked by At

I want to distribute my python script in pyc format(generated by python -OO -m py_compile run.py)

For different python versions, I've created run.cpython-36.pyc, run.cpython-38.pyc...

Now, if the users are using python3.6, they need to call python run.cpython-36.pyc, if they are using python3.8. they need to call python run.cpython-38.pyc. This is not convenient, how can I make python to auto-select the right pyc file to execute such that the user don't need to bother choosing the right version?

1

There are 1 best solutions below

0
konchy On

I figured out one solution: use a proxy script.

Something like:

# run_proxy.py

try:
  import run_36 as m
except ImportError:
  import run_38 as m

if __name__ == "__main__":
  # delegation
  m.Run()

And the users just call python run_proxy.py