Files
pytorch/torch/csrc/python_headers.h
David Reiss 6daaeb2bda [pytorch] Add C++ error when PyTorch used with Python 2
Summary: Python 2 has reached end-of-life and is no longer supported by PyTorch. To avoid confusing behavior when trying to use PyTorch with Python 2, detect this case early and fail with a clear message in C++.

Test Plan: waitforsandcastle

Reviewed By: orionr

Differential Revision: D21043062

fbshipit-source-id: ab448d2888f5048a0180598b882adfc67e31d851
2020-05-12 12:33:47 -07:00

19 lines
433 B
C

#pragma once
// workaround for Python 2 issue: https://bugs.python.org/issue17120
#pragma push_macro("_XOPEN_SOURCE")
#pragma push_macro("_POSIX_C_SOURCE")
#undef _XOPEN_SOURCE
#undef _POSIX_C_SOURCE
#include <Python.h>
#include <structseq.h>
#pragma pop_macro("_XOPEN_SOURCE")
#pragma pop_macro("_POSIX_C_SOURCE")
#if PY_MAJOR_VERSION < 3
#error "Python 2 has reached end-of-life and is no longer supported by PyTorch."
#endif