diff --git a/CMakeLists.txt b/CMakeLists.txt
index f1d468ef16a64ab27373a4b0926710d1001a0d44..1c8a30abbe9da6d81305443f65e906e098efabf7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -80,7 +80,7 @@ else()
   set(PYTHON_COMPONENTS Interpreter Development.Module NumPy)
 endif()
 set(PYTHON_EXPORT_DEPENDENCY ON)
-findpython()
+findpython(REQUIRED)
 
 if(WIN32)
   link_directories(${PYTHON_LIBRARY_DIRS})
diff --git a/include/eigenpy/memory.hpp b/include/eigenpy/memory.hpp
index f6f75f101a09d64fa7e4ef26ea72734dd6cde11e..447694e419dba3db69f1e0e13bb4cb578a8ab0a7 100644
--- a/include/eigenpy/memory.hpp
+++ b/include/eigenpy/memory.hpp
@@ -1,6 +1,6 @@
 /*
  * Copyright 2014-2019, CNRS
- * Copyright 2018-2019, INRIA
+ * Copyright 2018-2022, INRIA
  */
 
 #ifndef __eigenpy_memory_hpp__
@@ -8,6 +8,13 @@
 
 #include "eigenpy/fwd.hpp"
 
+#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_SIZE)
+static inline void _Py_SET_SIZE(PyVarObject* ob, Py_ssize_t size) {
+  ob->ob_size = size;
+}
+#define Py_SET_SIZE(ob, size) _Py_SET_SIZE((PyVarObject*)(ob), size)
+#endif
+
 /**
  * This section contains a convenience MACRO which allows an easy specialization
  * of Boost Python Object allocator for struct data types containing Eigen
@@ -66,7 +73,7 @@
             reinterpret_cast<Py_ssize_t>(holder) -                             \
             reinterpret_cast<Py_ssize_t>(&instance->storage) +                 \
             static_cast<Py_ssize_t>(offsetof(instance_t, storage));            \
-        Py_SIZE(instance) = holder_offset;                                     \
+        Py_SET_SIZE(instance, holder_offset);                                  \
                                                                                \
         protect.cancel();                                                      \
       }                                                                        \