import compileall class MyPath(str): pass compileall.compile_file(MyPath(__file__), force=True, quiet=True)