astropy: Importing astropy.coordinates fails with python -OO flag
Description
I am seeing an issue very similar to this: https://github.com/astropy/astropy/issues/10361
Issue 10361 was for astropy.units. I now see the same issue with astropy.coordinates.
Expected behavior
I expect to be able to import astropy.coordinates in a .py file and run the file in python.
How to Reproduce
Steps to Reproduce run python -OO test_script.py, where test_script.py is below:
import astropy.coordinates as apcoord
pass
Versions
Windows-10-10.0.19045-SP0 Python 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)] astropy 5.3 Numpy 1.25.0 pyerfa 2.0.0.3 Scipy 1.11.1 Matplotlib 3.7.2
Problem reproduced on Centos7/ Python3.9
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 17 (16 by maintainers)
I ran a slightly more complex test using the patched Astropy code with the newly patched Nuitka code (not yet in version available form pip, see https://github.com/Nuitka/Nuitka/issues/2313) and got the same error message I got last week. The original instructions I provided to reproduce the issue were too simplified to show the full scope of the problem. Or maybe this is a separate issue.
Slightly more complex test instructions: Create minimalTest.py with the following text:
Confirm it works in python. Should output sys.flags optimize=2 and ‘hello world.’
python3 -OO minimalTest.py
With the fix https://github.com/astropy/astropy/pull/15037/files, the only change without the -OO flag is that optimize=0.Compile using Nuitka and run the resulting executable.
I observed the same result with and without “–python-flag=-OO,” with the exception of the optimize flag.
Output of minimalTest.bin:
This error message looks very similar to https://github.com/astropy/astropy/issues/10361, but I think today’s fix should have resolved the related issue.
At this point, I don’t know whether the problem is in Astropy or Nuitka. Does Astropy require optimize flag=2 when python-flag = -OO? Currently Nuitka sets optimize=1 for flag -OO. (See https://github.com/Nuitka/Nuitka/issues/2313)
Note that we discussed upgrading PLY before, but apparently this is not trivial because they changed their implementation quite drastically: #13399. Given more recent changes in PLY, it may be less work than before to adapt our usage to it (but that’s better for discussion in #13399 itself).
Let me see if this works before committing to an upgrade. I don’t have high hopes that this will fix my problem, but I’m out of ideas of things to try that I know how to implement.
Yes there is:
sys.flags.optimize
.