Skip to content

Commit 643fdc3

Browse files
andfoyfmassa
andcommitted
Fix wheel relocation issues (#2777)
* [DEBUG] Check wheel relocation issues * Call delocate on Mac * Use yum instead of conda * Do not copy ffmpeg dylibs * Linux dry run * Do not download FFmpeg on Mac * Install bzip2 * Restore FFmpeg on Windows * Remove ffmpeg temporarily * Do not remove dependencies * Disable FFmpeg temporarily on Linux wheels * Test relocation in Linux * Add docstring * Call relocation script * Minor error correction * Import auditwheel only on Linux * Restore ffmpeg again on Windows * Return *device * Try fix Windows * Fix clang-format * Start windows patchwork * Copy all DLLs * Disable FFmpeg on Windows for now * Bugfix Co-authored-by: Francisco Massa <[email protected]>
1 parent 02c2537 commit 643fdc3

File tree

4 files changed

+457
-33
lines changed

4 files changed

+457
-33
lines changed

packaging/build_wheel.sh

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@ if [[ "$(uname)" == Darwin || "$OSTYPE" == "msys" ]]; then
1717
bin_path=$(dirname $python_exec)
1818
env_path=$(dirname $bin_path)
1919
if [[ "$(uname)" == Darwin ]]; then
20-
# Include LibPNG
21-
cp "$env_path/lib/libpng16.dylib" torchvision
22-
# Include LibJPEG
23-
cp "$env_path/lib/libjpeg.dylib" torchvision
20+
# Install delocate to relocate the required binaries
21+
pip_install delocate
2422
else
2523
cp "$bin_path/Library/bin/libpng16.dll" torchvision
2624
cp "$bin_path/Library/bin/libjpeg.dll" torchvision
2725
fi
2826
else
29-
# Include LibPNG
30-
cp "/usr/lib64/libpng.so" torchvision
31-
# Include LibJPEG
32-
cp "/usr/lib64/libjpeg.so" torchvision
27+
# Install auditwheel to get some inspection utilities
28+
pip_install auditwheel
29+
30+
# Point to custom libraries
31+
export LD_LIBRARY_PATH=$(pwd)/ext_libraries/lib:$LD_LIBRARY_PATH
32+
export TORCHVISION_INCLUDE=$(pwd)/ext_libraries/include
33+
export TORCHVISION_LIBRARY=$(pwd)/ext_libraries/lib
3334
fi
3435

3536

@@ -38,3 +39,20 @@ if [[ "$OSTYPE" == "msys" ]]; then
3839
else
3940
IS_WHEEL=1 python setup.py bdist_wheel
4041
fi
42+
43+
44+
if [[ "$(uname)" == Darwin ]]; then
45+
pushd dist/
46+
python_exec="$(which python)"
47+
bin_path=$(dirname $python_exec)
48+
env_path=$(dirname $bin_path)
49+
for whl in *.whl; do
50+
DYLD_LIBRARY_PATH="$env_path/lib/:$DYLD_LIBRARY_PATH" delocate-wheel -v $whl
51+
done
52+
else
53+
if [[ "$OSTYPE" == "msys" ]]; then
54+
"$script_dir/windows/internal/vc_env_helper.bat" python $script_dir/wheel/relocate.py
55+
else
56+
LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" python $script_dir/wheel/relocate.py
57+
fi
58+
fi

packaging/pkg_helpers.bash

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ setup_wheel_python() {
184184
# Install libpng from Anaconda (defaults)
185185
conda install libpng jpeg -y
186186
else
187-
# Install native CentOS libPNG
188-
yum install -y libpng-devel libjpeg-turbo-devel
187+
# Install native CentOS libJPEG, LAME, freetype and GnuTLS
188+
yum install -y libjpeg-turbo-devel lame freetype gnutls
189189
case "$PYTHON_VERSION" in
190190
2.7)
191191
if [[ -n "$UNICODE_ABI" ]]; then
@@ -203,7 +203,13 @@ setup_wheel_python() {
203203
exit 1
204204
;;
205205
esac
206-
export PATH="/opt/python/$python_abi/bin:$PATH"
206+
# Download all the dependencies required to compile image and video_reader
207+
# extensions
208+
209+
mkdir -p ext_libraries
210+
pushd ext_libraries
211+
popd
212+
export PATH="/opt/python/$python_abi/bin:$(pwd)/ext_libraries/bin:$PATH"
207213
fi
208214
}
209215

@@ -353,10 +359,8 @@ setup_junit_results_folder() {
353359

354360

355361
download_copy_ffmpeg() {
356-
mkdir ffmpeg_tmp
357-
cd ffmpeg_tmp
358362
if [[ "$OSTYPE" == "msys" ]]; then
359-
# conda install -yq ffmpeg -c pytorch
363+
# conda install -yq ffmpeg=4.2 -c pytorch
360364
# curl -L -q https://anaconda.org/pytorch/ffmpeg/4.3/download/win-64/ffmpeg-4.3-ha925a31_0.tar.bz2 --output ffmpeg-4.3-ha925a31_0.tar.bz2
361365
# bzip2 --decompress --stdout ffmpeg-4.3-ha925a31_0.tar.bz2 | tar -x --file=-
362366
# cp Library/bin/*.dll ../torchvision
@@ -365,24 +369,15 @@ download_copy_ffmpeg() {
365369
if [[ "$(uname)" == Darwin ]]; then
366370
conda install -yq ffmpeg=4.2 -c pytorch
367371
conda install -yq wget
368-
wget -q https://anaconda.org/pytorch/ffmpeg/4.2/download/osx-64/ffmpeg-4.2-h0a44026_0.tar.bz2
369-
tar -xjvf ffmpeg-4.2-h0a44026_0.tar.bz2
370-
for f in lib/*.dylib; do
371-
if [[ $f =~ ([a-z])+\.dylib ]]; then
372-
cp $f ../torchvision
373-
fi
374-
done
375372
else
376-
wget -q https://anaconda.org/pytorch/ffmpeg/4.2/download/linux-64/ffmpeg-4.2-hf484d3e_0.tar.bz2
377-
tar -xjvf ffmpeg-4.2-hf484d3e_0.tar.bz2
378-
cp lib/*.so ../torchvision
379-
cp -r lib/* /usr/lib
380-
cp -r bin/* /usr/bin
381-
cp -r include/* /usr/include
382-
ldconfig
383-
which ffmpeg
373+
# pushd ext_libraries
374+
# wget -q https://anaconda.org/pytorch/ffmpeg/4.2/download/linux-64/ffmpeg-4.2-hf484d3e_0.tar.bz2
375+
# tar -xjvf ffmpeg-4.2-hf484d3e_0.tar.bz2
376+
# rm -rf ffmpeg-4.2-hf484d3e_0.tar.bz2
377+
# ldconfig
378+
# which ffmpeg
379+
# popd
380+
echo "FFmpeg is disabled currently on Linux"
384381
fi
385382
fi
386-
cd ..
387-
rm -rf ffmpeg_tmp
388383
}

0 commit comments

Comments
 (0)