import py_compile sourceFile = 'd:/test.py' targetFile = 'd:/test.pyc' py_compile.compile(sourceFile, cfile = targetFile)