Cannot build PyTorch on windows, meet cannot open `tbb.lib'

Hi,
I want to build pytorch from source on windows. I follow the step in the official github site, and all required dependencies are installed.

However, when i run ``python setup.py build", i meet the following error:

LINK: fatal error LNK1104: cannot open file `tbb.lib’ [C:\Users\yizhiw\pytorch\build\caffe2\apply_utils_test.vcxproj]

A complete error report is as:

The Visual studio is 2017, and i use anaconda 3 with python 3.6.

Please help me!

It seems the error is brought by caffe2.
Actually, i do not need caffe2, is it possible to build without caffe2?

@magicwyzh I could reproduce this. Could you please send this to the github repo?

And the temporary workground is to install tbb through conda or pip using conda install tbb or pip install tbb.

I’m facing the same issue.
I’m rather new to all this, so I’m assuming I’m just doing something wrong with/in my setup script
(I’ve tried the default in the readme, and the various solutions from issue tracker, this is the latest ensemble I’ve tried)

conda create -n pyto python=3.6 -y
activate pyto

conda install numpy pyyaml mkl mkl-include setuptools cmake cffi typing pandas seaborn plotly scipy statsmodels jupyter notebook cython tbb -y
pip --no-cache-dir install cufflinks 
pip --no-cache-dir install sklearn
pip --no-cache-dir install tbb

cd %USERPROFILE%
git clone --recursive https://github.com/pytorch/pytorch
cd pytorch

python setup.py clean

set ANACONDA_ROOT=%USERPROFILE%\Anaconda3
set MKLProductDIR=C:\Program Files (x86)\IntelSWTools\compilers_and_libraries\windows

set USER_LDFLAGS=/LIBPATH:%ANACONDA_ROOT%\envs\pyto\Library\lib

set "VS150COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build"
set CMAKE_GENERATOR=Visual Studio 15 2017 Win64

set DISTUTILS_USE_SDK=1
call "%VS150COMNTOOLS%\vcvarsall.bat" x64 -vcvars_ver=14.11
set CMAKE_INCLUDE_PATH=%ANACONDA_ROOT%\envs\pyto\Library\include

set LIB=%MKLProductDir%\mkl\lib\intel64;%LIB%
set LIB=%MKLProductDIR%\tbb\lib\intel64\vc14;%LIB%
set LIB=%ANACONDA_ROOT%\Library\lib;%LIB%
set LIB=%ANACONDA_ROOT%\envs\pyto\Library\lib;%LIB%

set LD_LIBRARY_PATH=%MKLProductDIR%\tbb\lib\intel64\vc14;%LD_LIBRARY_PATH%
set LIBRARY_PATH=%MKLProductDIR%\tbb\lib\intel64\vc14;%LIBRARY_PATH%
set CMAKE_INCLUDE_PATH=%MKLProductDIR%\mkl\include;%CMAKE_INCLUDE_PATH%

python setup.py install

I installed both tbb and mkl from intel and I think I’ve installed the right packages from visual studio. I’m using anaconda3 5.2 with 3.6

Any insight into my issue will be much appreciated!

Hi, could you please extend the USER_LDFLAGS a little bit, like the following steps?

set USER_LDFLAGS=/LIBPATH:%ANACONDA_ROOT%\envs\pyto\Library\lib /LIBPATH:%MKLProductDir%\mkl\lib\intel64 /LIBPATH:%MKLProductDir%\mkl\lib\intel64\vc14 /LIBPATH:%ANACONDA_ROOT%\Library\lib

If the issue persists, would you please clean the build first?

python setup.py clean

I fail to find the words to express my appreciation @peterjc123!

I’ll note a few extra caveats I encountered in case someone else has the same problems I did.

My paths for the intel components contain invalid characters (namely spaces) which led to an error like:
The C compiler "*\cl.exe" is not able to compile a simple test program.
Reinstalling to a valid path like C:\IntelSWTools fixed that problem.
Then I encountered a LNK 1257 : code generation failed error, which stemmed from having VC++ 2015.3 v14.00 (v140) (in previous screen shot, installed). Since this package is a requirement during the installation of the nvidia components for windows there probably should be an explicit step/reminder in the readme for it’s removal

My final build script is a combination of the the information provided here and these issues:

conda create -n pyto python=3.6 -y
activate pyto

conda install numpy pyyaml mkl mkl-include setuptools cmake cffi typing pandas seaborn plotly scipy statsmodels jupyter notebook cython tbb -y
pip --no-cache-dir install cufflinks 
pip --no-cache-dir install sklearn
pip --no-cache-dir install tbb

cd %USERPROFILE%
git clone --recursive https://github.com/pytorch/pytorch
cd pytorch

python setup.py clean

set "VS150COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build"
set CMAKE_GENERATOR=Visual Studio 15 2017 Win64

set DISTUTILS_USE_SDK=1
call "%VS150COMNTOOLS%\vcvarsall.bat" x64 -vcvars_ver=14.11

set ANACONDA_ROOT=%USERPROFILE%\Anaconda3
export CMAKE_PREFIX_PATH=%ANACONDA_ROOT%\envs\pyto
set MKLProductDIR=C:\IntelSWTools\compilers_and_libraries_2018.3.210\windows

set USER_LDFLAGS=/LIBPATH:%ANACONDA_ROOT%\envs\pyto\Library\lib /LIBPATH:%MKLProductDir%\mkl\lib\intel64_win /LIBPATH:%MKLProductDir%\tbb\lib\intel64\vc14 /LIBPATH:%ANACONDA_ROOT%\Library\lib
set CMAKE_INCLUDE_PATH=%ANACONDA_ROOT%\envs\pyto\Library\include

set LIB=%MKLProductDir%\mkl\lib\intel64_win;%LIB%
set LIB=%MKLProductDIR%\tbb\lib\intel64_win\vc14;%LIB%
set LIB=%ANACONDA_ROOT%\Library\lib;%LIB%
set LIB=%ANACONDA_ROOT%\envs\pyto\Library\lib;%LIB%

set LD_LIBRARY_PATH=%MKLProductDIR%\tbb\lib\intel64_win\vc14;%LD_LIBRARY_PATH%
set LIBRARY_PATH=%MKLProductDIR%\tbb\lib\intel64_win\vc14;%LIBRARY_PATH%
set CMAKE_INCLUDE_PATH=%MKLProductDIR%\mkl\include;%CMAKE_INCLUDE_PATH%

python setup.py install

Cheers,
A.Noob