1

I'm trying to install pytorch

python setup.py install

but it fails as it can't locate libavutil/motion_vector.h

[ 66%] Building CXX object caffe2/CMakeFiles/torch.dir/video/video_input_op.cc.o
In file included from /root/pytorch/caffe2/video/video_input_op.h:15:0,
                 from /root/pytorch/caffe2/video/video_input_op.cc:1:
/root/pytorch/caffe2/video/video_decoder.h:15:37: fatal error: libavutil/motion_vector.h: No such file or directory
 #include <libavutil/motion_vector.h>
                                     ^
compilation terminated.
[ 66%] Building CXX object caffe2/CMakeFiles/torch.dir/video/video_io.cc.o
make[2]: *** [caffe2/CMakeFiles/torch.dir/video/video_input_op.cc.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from /root/pytorch/caffe2/video/video_io.h:6:0,
                 from /root/pytorch/caffe2/video/video_io.cc:1:
/root/pytorch/caffe2/video/video_decoder.h:15:37: fatal error: libavutil/motion_vector.h: No such file or directory
 #include <libavutil/motion_vector.h>
                                     ^
compilation terminated.
make[2]: *** [caffe2/CMakeFiles/torch.dir/video/video_io.cc.o] Error 1
make[1]: *** [caffe2/CMakeFiles/torch.dir/all] Error 2
make: *** [all] Error 2
Traceback (most recent call last):
  File "setup.py", line 759, in <module>
    build_deps()
  File "setup.py", line 321, in build_deps
    cmake=cmake)
  File "/root/pytorch/tools/build_pytorch_libs.py", line 63, in build_caffe2
    cmake.build(my_env)
  File "/root/pytorch/tools/setup_helpers/cmake.py", line 330, in build
    self.run(build_args, my_env)
  File "/root/pytorch/tools/setup_helpers/cmake.py", line 143, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "/usr/lib/python2.7/subprocess.py", line 540, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '-j', '12']' returned non-zero exit status 2

What I've tried so far:

Any other ideas?

Zahra
  • 6,798
  • 9
  • 51
  • 76
  • 1
    Why don't you use a simple `pip install`? – igrinis Sep 10 '19 at 07:03
  • OpenCV and ffmpeg are not built into it by default so I need to enable `USE_OPENCV` and `USE_FFMPEG` – Zahra Sep 10 '19 at 14:18
  • `USE_LMDB` too. – Zahra Sep 10 '19 at 14:30
  • What OS/version are you on? Did you check that the header exists and make looks for it in the correct location? I suggest you to open the script and locate which step fails exactly (by executing it step by step or adding prints) and when you narrow it down to specific make command report it here along with the version of cmake (cmake --version) and libavutil-dev. – isp-zax Sep 15 '19 at 20:47
  • Use anaconda ... – M__ Sep 16 '19 at 09:59
  • @MichaelG. does anaconda's build of pytorch include ffmpeg and opencv along with caffe? – Zahra Sep 16 '19 at 14:07
  • @isp-zax `Ubuntu 18.04.2 LTS`. I have tried two versions of cmake, `cmake 3.x` and `2.x`, in anticipation that it may be caused by cmake build process. The failure is simply caused by an include header file. I have also tried adding the missing `x.h` file in a path that cmake reaches. The only thing that I have not quite completely try is to change my cmake build files but I'm hoping there'd be an easir solution to install pytorch with caffe/opencv/ffmpeg that does not require all my hacky changes here and there. – Zahra Sep 16 '19 at 14:14
  • @Zahra Yes conda will do this. Full answered below. – M__ Sep 16 '19 at 16:41

2 Answers2

0

Missing headers of libraries commonly indicate missing development packages. For Debian and Ubuntu the package you are looking for is most likely called libavutil-dev. Try installing this package using you package manager and re-running the pip installation. For Fedora and SUSE the package should end with -devel.

hnzlmnn
  • 393
  • 2
  • 14
  • As already mentioned in my question, `libavutil-dev` is installed. Also, I'm not using `pip` for reasons described in my previous comments. **Kindly read the question and its comments before posting an answer**. – Zahra Sep 16 '19 at 14:04
0

For conda installation, firstly create an env, very important because you've used pip (pip stops conda seeing it's base env).

conda create -n pytorch_env python=3.7
source activate pytorch_env

conda install -c anaconda mkl

Then install pytorch and torch vision

conda install -c pytorch pytorch torchvision

You might want to run these as administrator, for me not needed. You will need to install Caffe via

conda install -c caffe2 pytorch-nightly

There's a bug for caffe2 installation (not nightly). Corrected below,

conda create -n pytorch_env python=3.6
source activate pytorch_env
conda install -c caffe2 caffe2

Having done this I found opencv and ffmpeg were loaded .. I can only assume they were a dependency of caffe2. Thus in summary yes you can do the whole thing easily via conda once the 3.7 -> 3.6 bug is resolved

M__
  • 614
  • 2
  • 10
  • 25
  • 1
    Unfortunately, this did not give me the desired pytorch/caffe2 installation either! I appreciate the help though. Awarding you the bounty anyways! – Zahra Sep 17 '19 at 18:07
  • Thank you @Zahra, much appreciated. I'm sorry this didn't work though :-( – M__ Sep 17 '19 at 21:22