Unverified Commit 53670211 authored by Nicolas Hug's avatar Nicolas Hug Committed by GitHub
Browse files

Remove include Python.h (#8413)

parent e4d2d1ad
...@@ -7,7 +7,6 @@ option(WITH_CUDA "Enable CUDA support" OFF) ...@@ -7,7 +7,6 @@ option(WITH_CUDA "Enable CUDA support" OFF)
option(WITH_MPS "Enable MPS support" OFF) option(WITH_MPS "Enable MPS support" OFF)
option(WITH_PNG "Enable features requiring LibPNG." ON) option(WITH_PNG "Enable features requiring LibPNG." ON)
option(WITH_JPEG "Enable features requiring LibJPEG." ON) option(WITH_JPEG "Enable features requiring LibJPEG." ON)
option(USE_PYTHON "Link to Python when building" OFF)
if(WITH_CUDA) if(WITH_CUDA)
enable_language(CUDA) enable_language(CUDA)
...@@ -33,11 +32,6 @@ if (WITH_JPEG) ...@@ -33,11 +32,6 @@ if (WITH_JPEG)
find_package(JPEG REQUIRED) find_package(JPEG REQUIRED)
endif() endif()
if (USE_PYTHON)
add_definitions(-DUSE_PYTHON)
find_package(Python3 REQUIRED COMPONENTS Development)
endif()
function(CUDA_CONVERT_FLAGS EXISTING_TARGET) function(CUDA_CONVERT_FLAGS EXISTING_TARGET)
get_property(old_flags TARGET ${EXISTING_TARGET} PROPERTY INTERFACE_COMPILE_OPTIONS) get_property(old_flags TARGET ${EXISTING_TARGET} PROPERTY INTERFACE_COMPILE_OPTIONS)
if(NOT "${old_flags}" STREQUAL "") if(NOT "${old_flags}" STREQUAL "")
...@@ -110,10 +104,6 @@ if (WITH_JPEG) ...@@ -110,10 +104,6 @@ if (WITH_JPEG)
target_link_libraries(${PROJECT_NAME} PRIVATE ${JPEG_LIBRARIES}) target_link_libraries(${PROJECT_NAME} PRIVATE ${JPEG_LIBRARIES})
endif() endif()
if (USE_PYTHON)
target_link_libraries(${PROJECT_NAME} PRIVATE Python3::Python)
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES set_target_properties(${PROJECT_NAME} PROPERTIES
EXPORT_NAME TorchVision EXPORT_NAME TorchVision
INSTALL_RPATH ${TORCH_INSTALL_PREFIX}/lib) INSTALL_RPATH ${TORCH_INSTALL_PREFIX}/lib)
......
...@@ -46,13 +46,5 @@ if(@WITH_JPEG@) ...@@ -46,13 +46,5 @@ if(@WITH_JPEG@)
target_compile_definitions(${PN}::${PN} INTERFACE JPEG_FOUND) target_compile_definitions(${PN}::${PN} INTERFACE JPEG_FOUND)
endif() endif()
if (@USE_PYTHON@)
if(NOT TARGET Python3::Python)
find_package(Python3 COMPONENTS Development)
endif()
target_link_libraries(torch INTERFACE Python3::Python)
target_compile_definitions(${PN}::${PN} INTERFACE USE_PYTHON)
endif()
endif() endif()
endif() endif()
...@@ -81,9 +81,6 @@ cmake --install . ...@@ -81,9 +81,6 @@ cmake --install .
You may want to pass `-DCMAKE_INSTALL_PREFIX=/path/to/libtorchvision` for You may want to pass `-DCMAKE_INSTALL_PREFIX=/path/to/libtorchvision` for
cmake to copy/install the files to a specific location (e.g. `$CONDA_PREFIX`). cmake to copy/install the files to a specific location (e.g. `$CONDA_PREFIX`).
On Windows, you may also need to pass `-DUSE_PYTHON`. Refer to the corresponding
`CMakeLists.txt` for additional options.
**DISCLAIMER**: the `libtorchvision` library includes the torchvision **DISCLAIMER**: the `libtorchvision` library includes the torchvision
custom ops as well as most of the C++ torchvision APIs. Those APIs do not come custom ops as well as most of the C++ torchvision APIs. Those APIs do not come
with any backward-compatibility guarantees and may change from one version to with any backward-compatibility guarantees and may change from one version to
......
...@@ -209,7 +209,6 @@ def get_extensions(): ...@@ -209,7 +209,6 @@ def get_extensions():
if sys.platform == "win32": if sys.platform == "win32":
define_macros += [("torchvision_EXPORTS", None)] define_macros += [("torchvision_EXPORTS", None)]
define_macros += [("USE_PYTHON", None)]
extra_compile_args["cxx"].append("/MP") extra_compile_args["cxx"].append("/MP")
if debug_mode: if debug_mode:
...@@ -254,9 +253,6 @@ def get_extensions(): ...@@ -254,9 +253,6 @@ def get_extensions():
image_library = [] image_library = []
image_link_flags = [] image_link_flags = []
if sys.platform == "win32":
image_macros += [("USE_PYTHON", None)]
# Locating libPNG # Locating libPNG
libpng = shutil.which("libpng-config") libpng = shutil.which("libpng-config")
pngfix = shutil.which("pngfix") pngfix = shutil.which("pngfix")
......
#include "image.h" #include "image.h"
#include <ATen/core/op_registration/op_registration.h> #include <ATen/core/op_registration/op_registration.h>
#ifdef USE_PYTHON
#include <Python.h>
#endif
// If we are in a Windows environment, we need to define // If we are in a Windows environment, we need to define
// initialization functions for the _custom_ops extension // initialization functions for the _custom_ops extension
#ifdef USE_PYTHON
#ifdef _WIN32 #ifdef _WIN32
PyMODINIT_FUNC PyInit_image(void) { void* PyInit_image(void) {
// No need to do anything.
return nullptr; return nullptr;
} }
#endif #endif
#endif // USE_PYTHON
namespace vision { namespace vision {
namespace image { namespace image {
......
#include "video_reader.h" #include "video_reader.h"
#ifdef USE_PYTHON
#include <Python.h>
#endif
#include "../decoder/memory_buffer.h" #include "../decoder/memory_buffer.h"
#include "../decoder/sync_decoder.h" #include "../decoder/sync_decoder.h"
#ifdef USE_PYTHON
// If we are in a Windows environment, we need to define // If we are in a Windows environment, we need to define
// initialization functions for the _custom_ops extension // initialization functions for the _custom_ops extension
#ifdef _WIN32 #ifdef _WIN32
PyMODINIT_FUNC PyInit_video_reader(void) { void* PyInit_video_reader(void) {
// No need to do anything.
return nullptr; return nullptr;
} }
#endif #endif
#endif // USE_PYTHONs
using namespace ffmpeg; using namespace ffmpeg;
......
#include "vision.h" #include "vision.h"
#ifndef MOBILE
#ifdef USE_PYTHON
#include <Python.h>
#endif
#endif
#include <torch/library.h> #include <torch/library.h>
#ifdef WITH_CUDA #ifdef WITH_CUDA
...@@ -16,14 +11,10 @@ ...@@ -16,14 +11,10 @@
// If we are in a Windows environment, we need to define // If we are in a Windows environment, we need to define
// initialization functions for the _custom_ops extension. // initialization functions for the _custom_ops extension.
// For PyMODINIT_FUNC to work, we need to include Python.h
#if !defined(MOBILE) && defined(_WIN32) #if !defined(MOBILE) && defined(_WIN32)
#ifdef USE_PYTHON void* PyInit__C(void) {
PyMODINIT_FUNC PyInit__C(void) {
// No need to do anything.
return nullptr; return nullptr;
} }
#endif // USE_PYTHON
#endif // !defined(MOBILE) && defined(_WIN32) #endif // !defined(MOBILE) && defined(_WIN32)
namespace vision { namespace vision {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment