2

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?

2
  • 3
    Does whoever forces you to use -O realize that the "optimizations" are pretty much stripping assertions and do nothing else? Commented Feb 11, 2011 at 16:09
  • I'm running Python under IIS through PyISAPIe and it runs in optimized mode (I've done no investigation on this) Commented Jun 4, 2015 at 7:23

2 Answers 2

3

One way to "convert" them is simply renaming them. Of course they won't be optimised, but at least you can use them.

Sign up to request clarification or add additional context in comments.

2 Comments

Specifically, assertions won't be stripped. But that won't make much of a difference... or at least it shouldn't. There's a surprising amount programmers that use assert for input validation.
It worked, thanks. This make me wonder why couldn't python import them by itself
2

You can use DePython to convert your .pyc files into .py files, and then you will be able to import them.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.