diff --git a/Include/internal/pycore_capsule.h b/Include/internal/pycore_capsule.h
new file mode 100644
index 00000000000..aa2c67f3a8f
--- /dev/null
+++ b/Include/internal/pycore_capsule.h
@@ -0,0 +1,17 @@
+#ifndef Py_INTERNAL_PYCAPSULE_H
+#define Py_INTERNAL_PYCAPSULE_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef Py_BUILD_CORE
+# error "this header requires Py_BUILD_CORE define"
+#endif
+
+// Export for '_socket' shared extension
+PyAPI_FUNC(int) _PyCapsule_SetTraverse(PyObject *op, traverseproc traverse_func, inquiry clear_func);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* !Py_INTERNAL_PYCAPSULE_H */
diff --git a/Include/pycapsule.h b/Include/pycapsule.h
index 8660e83088e..666b9f86739 100644
--- a/Include/pycapsule.h
+++ b/Include/pycapsule.h
@@ -48,15 +48,10 @@ PyAPI_FUNC(int) PyCapsule_SetName(PyObject *capsule, const char *name);
PyAPI_FUNC(int) PyCapsule_SetContext(PyObject *capsule, void *context);
-#ifdef Py_BUILD_CORE
-PyAPI_FUNC(int) _PyCapsule_SetTraverse(PyObject *op, traverseproc traverse_func, inquiry clear_func);
-#endif
-
PyAPI_FUNC(void *) PyCapsule_Import(
const char *name, /* UTF-8 encoded string */
int no_block);
-
#ifdef __cplusplus
}
#endif
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 62a55bb2478..310caa94b9e 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1743,6 +1743,7 @@ PYTHON_HEADERS= \
$(srcdir)/Include/internal/pycore_bytes_methods.h \
$(srcdir)/Include/internal/pycore_bytesobject.h \
$(srcdir)/Include/internal/pycore_call.h \
+ $(srcdir)/Include/internal/pycore_capsule.h \
$(srcdir)/Include/internal/pycore_ceval.h \
$(srcdir)/Include/internal/pycore_ceval_state.h \
$(srcdir)/Include/internal/pycore_code.h \
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 8cc45e22549..e3681853dad 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -106,6 +106,7 @@ Local naming conventions:
#endif
#include "Python.h"
+#include "pycore_capsule.h" // _PyCapsule_SetTraverse()
#include "pycore_dict.h" // _PyDict_Pop()
#include "pycore_fileutils.h" // _Py_set_inheritable()
#include "pycore_moduleobject.h" // _PyModule_GetState
diff --git a/Objects/capsule.c b/Objects/capsule.c
index a1abcf683f0..555979dab2b 100644
--- a/Objects/capsule.c
+++ b/Objects/capsule.c
@@ -1,6 +1,7 @@
/* Wrap void * pointers to be passed between C modules */
#include "Python.h"
+#include "pycore_capsule.h" // export _PyCapsule_SetTraverse()
#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED()
#include "pycore_object.h" // _PyObject_GC_TRACK()
diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
index bc1250f6395..9ab84702d1f 100644
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -206,6 +206,7 @@
+
diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters
index a8a11d3b8b8..d5c53a0c64b 100644
--- a/PCbuild/pythoncore.vcxproj.filters
+++ b/PCbuild/pythoncore.vcxproj.filters
@@ -528,6 +528,9 @@
Include\internal
+
+ Include\internal
+
Include\internal