让Python在优化模式下运行时导入.pyc
我必须使用一些遗留的 .pyc 模块(没有源代码),但我也被迫在优化模式下使用 python (python -O
):所以,当尝试导入这些模块时,我得到导入错误(因为 python 查找 .py 或 .pyo 文件)。
有没有办法让它也使用 pyc 模块?或者将 .pyc 转换为 .pyo?
I have to use some legacy .pyc modules (with no source) but I'm also forced to use python in optimized mode (python -O
): so, when trying to import those modules, I get an import error (as python looks for .py or .pyo files).
Is there a way to make it use pyc modules as well? Or to convert .pyc into .pyo?
“转换”它们的一种方法就是简单地重命名它们。当然它们不会被优化,但至少你可以使用它们。
One way to "convert" them is simply renaming them. Of course they won't be optimised, but at least you can use them.