Import precedence for different types of python extensions

I was doing some speed tests with cython in Windows and started wondering what the import precedence was between py, pyc, and pyd files (not to mention pyo). So I did a simple little test with two files, test.py and test2.py. Test.py just had a print statement in it and test2 just imported test1 (so it would create the pyc). I compiled test.py with cython into test.pyd and then changed test.py to print something else.

Conclusion: The pyd file was always imported if it was present. If it wasn’t there, then the new print statement from the new test.py was printed out. I’m sure this is documented somewhere but I’m not sure where. The conclusion holds if there are “optimized” pyo files present as well.

Leave a Reply

Your email address will not be published. Required fields are marked *