From 229ba1c445443be0d68296399d40b7d51f9f95e3 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Tue, 17 Dec 2024 14:31:50 +0100 Subject: [PATCH] GH-44855: [Python][Packaging] Do not bundle `msvcp140.dll` Bundling `msvcp140.dll` in Python Windows wheels risks crashes or undefined behavior if another Python package loads another version of the DLL. Instead of bundling this widespread DLL, we should let the user install it themselves in the (relatively unlikely) case it is not already available on the system. This ensures that a single DLL version is shared between all Python packages. --- ci/scripts/python_wheel_windows_build.bat | 2 -- python/pyarrow/__init__.py | 19 ++++++++++++++++++- python/setup.py | 6 ------ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/ci/scripts/python_wheel_windows_build.bat b/ci/scripts/python_wheel_windows_build.bat index 1f1d5dca721d9..b13aabb316f25 100644 --- a/ci/scripts/python_wheel_windows_build.bat +++ b/ci/scripts/python_wheel_windows_build.bat @@ -121,7 +121,5 @@ set ARROW_HOME=C:\arrow-dist set CMAKE_PREFIX_PATH=C:\arrow-dist pushd C:\arrow\python -@REM bundle the msvc runtime -cp "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Redist\MSVC\14.28.29325\x64\Microsoft.VC142.CRT\msvcp140.dll" pyarrow\ python setup.py bdist_wheel || exit /B 1 popd diff --git a/python/pyarrow/__init__.py b/python/pyarrow/__init__.py index d00a731324c92..5b03ae5c2305d 100644 --- a/python/pyarrow/__init__.py +++ b/python/pyarrow/__init__.py @@ -62,7 +62,24 @@ def parse_git(root, **kwargs): # to workaround Cython bug in https://github.com/cython/cython/issues/3603 _gc_enabled = _gc.isenabled() _gc.disable() -import pyarrow.lib as _lib + +try: + import pyarrow.lib as _lib +except ImportError: + if _os.name == 'nt': + # Give a clearer error message if the import failed because of missing + # the C++ runtime for MSVC (see GH-44855). + import ctypes + try: + ctypes.CDLL('msvcp140.dll') + except OSError: + raise ImportError( + "PyArrow import failure, presumably because the Microsoft Visual C++ " + "Redistributable is not installed. You can download it from " + "https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist") + # Other cases: re-raise original error + raise + if _gc_enabled: _gc.enable() diff --git a/python/setup.py b/python/setup.py index 60b9a696d9785..3ae1c5b8d4718 100755 --- a/python/setup.py +++ b/python/setup.py @@ -129,8 +129,6 @@ def run(self): ('extra-cmake-args=', None, 'extra arguments for CMake'), ('build-type=', None, 'build type (debug or release), default release'), - ('boost-namespace=', None, - 'namespace of boost (default: boost)'), ('with-cuda', None, 'build the Cuda extension'), ('with-flight', None, 'build the Flight extension'), ('with-substrait', None, 'build the Substrait extension'), @@ -144,14 +142,10 @@ def run(self): ('with-gcs', None, 'build the Google Cloud Storage (GCS) extension'), ('with-s3', None, 'build the Amazon S3 extension'), - ('with-static-parquet', None, 'link parquet statically'), - ('with-static-boost', None, 'link boost statically'), ('with-orc', None, 'build the ORC extension'), ('with-gandiva', None, 'build the Gandiva extension'), ('generate-coverage', None, 'enable Cython code coverage'), - ('bundle-boost', None, - 'bundle the (shared) Boost libraries'), ('bundle-cython-cpp', None, 'bundle generated Cython C++ code ' '(used for code coverage)'),