From ddbfdc911d94760bb431fcdf2a0322432c1c8272 Mon Sep 17 00:00:00 2001 From: Shuichi KITAGUCHI Date: Mon, 1 Apr 2019 07:24:27 -0700 Subject: [PATCH] Create torch/lib directory before copying _C.lib on Windows environment. (#18666) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Summary: `python setup.py develop` fails with following messages. ~~~ ... -- Building with NumPy bindings -- Not using cuDNN -- Not using MIOpen -- Not using CUDA -- Using MKLDNN -- Not using NCCL -- Building without distributed package Copying extension caffe2.python.caffe2_pybind11_state Copying caffe2.python.caffe2_pybind11_state from torch\Lib\site-packages\caffe2\python\caffe2_pybind11_state.cp37-win_amd64.pyd to C:\data\source\pytorch\build\lib.win-amd64-3.7\caffe2\python\caffe2_pybind11_state.cp37-win_amd64.pyd copying torch\Lib\site-packages\caffe2\python\caffe2_pybind11_state.cp37-win_amd64.pyd -> C:\data\source\pytorch\build\lib.win-amd64-3.7\caffe2\python building 'torch._C' extension creating build\temp.win-amd64-3.7 creating build\temp.win-amd64-3.7\Release creating build\temp.win-amd64-3.7\Release\torch creating build\temp.win-amd64-3.7\Release\torch\csrc ... creating C:\data\source\pytorch\build\lib.win-amd64-3.7\torch C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /nodefaultlib:libucrt.lib ucrt.lib /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\data\source\pytorch\torch\lib /LIBPATH:C:\data\dlenv\libs /LIBPATH:C:\data\dlenv\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.16.27023\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\um\x64" shm.lib torch_python.lib /EXPORT:PyInit__C build\temp.win-amd64-3.7\Release\torch/csrc/stub.obj /OUT:build\lib.win-amd64-3.7\torch\_C.cp37-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.7\Release\torch/csrc\_C.cp37-win_amd64.lib /NODEFAULTLIB:LIBCMT.LIB ライブラリ build\temp.win-amd64-3.7\Release\torch/csrc\_C.cp37-win_amd64.lib とオブジェクト build\temp.win-amd64-3.7\Release\torch/csrc\_C.cp37-win_amd64.exp を作成中 コード生成しています。 コード生成が終了しました。 copying build\lib.win-amd64-3.7\torch\_C.cp37-win_amd64.pyd -> torch copying build\lib.win-amd64-3.7\caffe2\python\caffe2_pybind11_state.cp37-win_amd64.pyd -> caffe2\python copying build/temp.win-amd64-3.7/Release/torch/csrc/_C.cp37-win_amd64.lib -> build/lib.win-amd64-3.7/torch/lib/_C.lib error: could not create 'build/lib.win-amd64-3.7/torch/lib/_C.lib': No such file or directory ~~~ When `python setup.py install` is executed, `torch/lib` has been created by previous process (copying many files) and this copy succeeds. But in develop mode, that process does not executed and this copy fails. This patch creates `torch/lib` directory if do not exist. Pull Request resolved: https://github.com/pytorch/pytorch/pull/18666 Differential Revision: D14704269 Pulled By: ezyang fbshipit-source-id: b2d7c698a906b945bf34bb78f17b91b4fdfd3294 --- setup.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/setup.py b/setup.py index baa5db5..21734ed 100644 --- a/setup.py +++ b/setup.py @@ -374,6 +374,12 @@ class build_ext(setuptools.command.build_ext.build_ext): target_lib = os.path.join( build_lib, 'torch', 'lib', '_C.lib').replace('\\', '/') + # Create "torch/lib" directory if not exists. + # (It is not created yet in "develop" mode.) + target_dir = os.path.dirname(target_lib) + if not os.path.exists(target_dir): + os.makedirs(target_dir) + self.copy_file(export_lib, target_lib) def build_extensions(self): -- 2.7.4