Code fails tests on 3.11. But, works on 3.8

I’m having issues with the various types in Helpers failing to import in 3.11, but they import fine in 3.8. Was there a specific behavior change that would break this code?

ImageDtype, Dtype, and dtypes fail to import. I believe it’s from circular dependencies in the file. If I break those types out into separate files the issue goes away, but that seems too granular. Is there anyway of building the objects in an intermediary file, and then importing it to a third?

Please try to create a minimal reproducible example so that we can understand the issue clearly.

The problem is when I split everything up the issue goes away. Give me a sec to get back to narrowing down to a minimal reproducible example.

Yeah, it’s hard to create a minimally reproducible example. I think it’s from a change between 3.8 to 3.11, and code in specific files creating issues when importing from one file.

Although the code posted is massive, if the error occurs during import, we are presumably only interested in the first 7 lines. At what point in the sequence, or a nested import, does it fail?

Everything except numpy is from the “stdlib” (I think) so we should be on safe ground with them (unless somewhere a module shades one of them).

I tried the first 7 lines in a virtualenv in both 3.11 and 3.8 and everything imports sweetly. (WIndows, 3.8.10 and 3.11.1.) I installed numpy separately in each virtualenv and was given different versions (numpy 1.24.4 and 1.25.1).

I wonder if you are using versions of a library (maybe even the stdlib) installed under 3.8 when running with 3.11? This may be the result of rolling your own PYTHONPATH. If I abusively copy my numpy1.24.4 installation into the 3.11 site-packages, I get import failures, but not exactly the ones you report. (Instead: No module named 'numpy.core._multiarray_umath')

1 Like

Could we at least see a complete stack trace for a failure?

You need numpy compiled specifically for 3.8 and 3.11 respectively. Do you?

Figured out the issue. Had something to do with me creating the Python virtual environment by command line, while running Pycharm.