Skip to content

Commit 5367021

Browse files
authored
Remove include Python.h (#8413)
1 parent e4d2d1a commit 5367021

File tree

7 files changed

+3
-50
lines changed

7 files changed

+3
-50
lines changed

CMakeLists.txt

-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ option(WITH_CUDA "Enable CUDA support" OFF)
77
option(WITH_MPS "Enable MPS support" OFF)
88
option(WITH_PNG "Enable features requiring LibPNG." ON)
99
option(WITH_JPEG "Enable features requiring LibJPEG." ON)
10-
option(USE_PYTHON "Link to Python when building" OFF)
1110

1211
if(WITH_CUDA)
1312
enable_language(CUDA)
@@ -33,11 +32,6 @@ if (WITH_JPEG)
3332
find_package(JPEG REQUIRED)
3433
endif()
3534

36-
if (USE_PYTHON)
37-
add_definitions(-DUSE_PYTHON)
38-
find_package(Python3 REQUIRED COMPONENTS Development)
39-
endif()
40-
4135
function(CUDA_CONVERT_FLAGS EXISTING_TARGET)
4236
get_property(old_flags TARGET ${EXISTING_TARGET} PROPERTY INTERFACE_COMPILE_OPTIONS)
4337
if(NOT "${old_flags}" STREQUAL "")
@@ -110,10 +104,6 @@ if (WITH_JPEG)
110104
target_link_libraries(${PROJECT_NAME} PRIVATE ${JPEG_LIBRARIES})
111105
endif()
112106

113-
if (USE_PYTHON)
114-
target_link_libraries(${PROJECT_NAME} PRIVATE Python3::Python)
115-
endif()
116-
117107
set_target_properties(${PROJECT_NAME} PROPERTIES
118108
EXPORT_NAME TorchVision
119109
INSTALL_RPATH ${TORCH_INSTALL_PREFIX}/lib)

cmake/TorchVisionConfig.cmake.in

-8
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,5 @@ if(@WITH_JPEG@)
4646
target_compile_definitions(${PN}::${PN} INTERFACE JPEG_FOUND)
4747
endif()
4848

49-
if (@USE_PYTHON@)
50-
if(NOT TARGET Python3::Python)
51-
find_package(Python3 COMPONENTS Development)
52-
endif()
53-
target_link_libraries(torch INTERFACE Python3::Python)
54-
target_compile_definitions(${PN}::${PN} INTERFACE USE_PYTHON)
55-
endif()
56-
5749
endif()
5850
endif()

examples/cpp/README.rst

-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ cmake --install .
8181
You may want to pass `-DCMAKE_INSTALL_PREFIX=/path/to/libtorchvision` for
8282
cmake to copy/install the files to a specific location (e.g. `$CONDA_PREFIX`).
8383

84-
On Windows, you may also need to pass `-DUSE_PYTHON`. Refer to the corresponding
85-
`CMakeLists.txt` for additional options.
86-
8784
**DISCLAIMER**: the `libtorchvision` library includes the torchvision
8885
custom ops as well as most of the C++ torchvision APIs. Those APIs do not come
8986
with any backward-compatibility guarantees and may change from one version to

setup.py

-4
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ def get_extensions():
209209

210210
if sys.platform == "win32":
211211
define_macros += [("torchvision_EXPORTS", None)]
212-
define_macros += [("USE_PYTHON", None)]
213212
extra_compile_args["cxx"].append("/MP")
214213

215214
if debug_mode:
@@ -254,9 +253,6 @@ def get_extensions():
254253
image_library = []
255254
image_link_flags = []
256255

257-
if sys.platform == "win32":
258-
image_macros += [("USE_PYTHON", None)]
259-
260256
# Locating libPNG
261257
libpng = shutil.which("libpng-config")
262258
pngfix = shutil.which("pngfix")

torchvision/csrc/io/image/image.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
#include "image.h"
22

33
#include <ATen/core/op_registration/op_registration.h>
4-
#ifdef USE_PYTHON
5-
#include <Python.h>
6-
#endif
74

85
// If we are in a Windows environment, we need to define
96
// initialization functions for the _custom_ops extension
10-
#ifdef USE_PYTHON
117
#ifdef _WIN32
12-
PyMODINIT_FUNC PyInit_image(void) {
13-
// No need to do anything.
8+
void* PyInit_image(void) {
149
return nullptr;
1510
}
1611
#endif
17-
#endif // USE_PYTHON
1812

1913
namespace vision {
2014
namespace image {

torchvision/csrc/io/video_reader/video_reader.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
#include "video_reader.h"
22

3-
#ifdef USE_PYTHON
4-
#include <Python.h>
5-
#endif
6-
73
#include "../decoder/memory_buffer.h"
84
#include "../decoder/sync_decoder.h"
95

10-
#ifdef USE_PYTHON
116
// If we are in a Windows environment, we need to define
127
// initialization functions for the _custom_ops extension
138
#ifdef _WIN32
14-
PyMODINIT_FUNC PyInit_video_reader(void) {
15-
// No need to do anything.
9+
void* PyInit_video_reader(void) {
1610
return nullptr;
1711
}
1812
#endif
19-
#endif // USE_PYTHONs
2013

2114
using namespace ffmpeg;
2215

torchvision/csrc/vision.cpp

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
#include "vision.h"
22

3-
#ifndef MOBILE
4-
#ifdef USE_PYTHON
5-
#include <Python.h>
6-
#endif
7-
#endif
83
#include <torch/library.h>
94

105
#ifdef WITH_CUDA
@@ -16,14 +11,10 @@
1611

1712
// If we are in a Windows environment, we need to define
1813
// initialization functions for the _custom_ops extension.
19-
// For PyMODINIT_FUNC to work, we need to include Python.h
2014
#if !defined(MOBILE) && defined(_WIN32)
21-
#ifdef USE_PYTHON
22-
PyMODINIT_FUNC PyInit__C(void) {
23-
// No need to do anything.
15+
void* PyInit__C(void) {
2416
return nullptr;
2517
}
26-
#endif // USE_PYTHON
2718
#endif // !defined(MOBILE) && defined(_WIN32)
2819

2920
namespace vision {

0 commit comments

Comments
 (0)