【问题标题】:fbtorch: cmake can not find torch directoriesfbtorch:cmake 找不到火炬目录
【发布时间】:2016-12-02 01:37:26
【问题描述】:

我正在尝试构建和安装 fbtorch,但是当我使用 cmake 时出现以下错误:

CMake Error at CMakeLists.txt:9 (FIND_PACKAGE):
  By not providing "FindTorch.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Torch", but
  CMake did not find one.

  Could not find a package configuration file provided by "Torch" with any of
  the following names:

    TorchConfig.cmake
    torch-config.cmake

  Add the installation prefix of "Torch" to CMAKE_PREFIX_PATH or set
  "Torch_DIR" to a directory containing one of the above files.  If "Torch"
  provides a separate development package or SDK, be sure it has been
  installed.

我在网上搜索,找到了一些解决方法,比如使用

source ~/torch/install/bin/torch-activate

或重新安装torch,但没有任何帮助。 有人可以帮我吗?谢谢。

【问题讨论】:

  • 应该有文件TorchConfig.cmake,是torch安装自带的。这个文件在你机器上的什么位置?
  • @Tsyvarev 我发现了两个 TorchConfig.cmake。一个在 install/share/cmake/torch,另一个在 pkg/torch/build/cmake-exports
  • 如错误消息所示,将变量 Torch_DIR 设置为包含该文件的目录。例如,调用 cmake 时:cmake -DTorch_DIR=install/share/cmake/torch ...

标签: cmake torch


【解决方案1】:

遇到同样的问题。

解决方案:在cmake之前将Torch_DIR导出为环境变量

例如我在linux上使用python虚拟环境,并使用'pip'安装了pytorch。

export Torch_DIR=/home/my/pyenv/py3.7-torch1.0/lib/python3.7/site-packages/torch/share/cmake/Torch

cmake blablabla
make

【讨论】:

    【解决方案2】:

    如果使用 clion:

    clion 偏好 --> 环境 ---> /some_path_to/torchscript/libtorch/share/cmake/Torch

    【讨论】:

      猜你喜欢
      • 2020-07-06
      • 2019-07-27
      • 2021-12-13
      • 2017-06-06
      • 2017-02-23
      • 1970-01-01
      • 2023-01-20
      • 1970-01-01
      • 2021-12-08
      相关资源
      最近更新 更多