Skip to content

Commit

Permalink
GH-44855: [Python][Packaging] Do not bundle msvcp140.dll
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pitrou committed Dec 17, 2024
1 parent 2fcf8b3 commit 229ba1c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 0 additions & 2 deletions ci/scripts/python_wheel_windows_build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 18 additions & 1 deletion python/pyarrow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 0 additions & 6 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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)'),
Expand Down

0 comments on commit 229ba1c

Please sign in to comment.