diff --git a/var/spack/repos/builtin/packages/py-astropy/package.py b/var/spack/repos/builtin/packages/py-astropy/package.py
index 1e85cbf070b6b0506c087cc15b4db9fe64f10a5b..40009e6d11226d4f632fcabdd5272d3ec74a6c30 100644
--- a/var/spack/repos/builtin/packages/py-astropy/package.py
+++ b/var/spack/repos/builtin/packages/py-astropy/package.py
@@ -4,6 +4,7 @@
 # SPDX-License-Identifier: (Apache-2.0 OR MIT)
 
 from spack import *
+import os
 
 
 class PyAstropy(PythonPackage):
@@ -52,6 +53,7 @@ class PyAstropy(PythonPackage):
     depends_on('py-asdf@2.3:', when='+extras', type=('build', 'run'))
     depends_on('py-bottleneck', when='+extras', type=('build', 'run'))
     depends_on('py-pytest', when='+extras', type=('build', 'run'))
+    depends_on('py-cython', type='build')
 
     # System dependencies
     depends_on('erfa')
@@ -59,6 +61,13 @@ class PyAstropy(PythonPackage):
     depends_on('cfitsio')
     depends_on('expat')
 
+    def patch(self):
+        # forces the rebuild of files with cython
+        # avoids issues with PyCode_New() in newer
+        # versions of python in the distributed
+        # cython-ized files
+        os.remove('astropy/cython_version.py')
+
     def build_args(self, spec, prefix):
         args = [
             '--use-system-libraries',