-
Notifications
You must be signed in to change notification settings - Fork 22.1k
-
Notifications
You must be signed in to change notification settings - Fork 22.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could not find a package configuration file provided by "Torch" with any of the following names: #12449
Comments
cc @goldsborough maybe? |
I'll take a look |
Any suggestions? |
Can you post the exact steps you took when you tried this? I assume you downloaded the latest libtorch, unzipped it, pointed your cmake at the folder etc? Could you post your terminal output with these commands? I'd like to understand the steps you took to arrive at this error. |
如果你不想下载源码,你也可以下载shared library的共享链接版本,这样下载:
此时我们就可以开始写一个小程序了,C++的。我们这里使用源码编译,不适用动态链接库。从下载的文件来看,最上面的文件是静态链接库,并没有源代码,说明核心的东西还是没有完全的放出来。我们先看看,如果用CMake来写一个小程序。 CMake设置我们现在看看cmake如何设置,简单的来说,只需要几行代码:
我们再来看看文件结构,首先我们已经下载好了
其中 cpp文件写入几行简单的c++代码:
最后我们写一个build.sh在编译,注意,我们直接指定 刚才的libtorch的路径即可。
直接运行, 好吧又是库的问题:
Above is the steps in Chinese but you can see the commands and setups I did. Just new a folder and write the CMakeLists.txt, and using
To builded it and ends the error. |
Can you try changing |
@goldsborough I am just runing this inside build folder as suggested as docs, I can see any difference between these two. But it's works and cmake config done. However after make, some new error got:
Is that not support for macos? But I just download the macos version .so library. |
Is it possible that you're using the Linux package instead of the MacOS package? The MacOS package is https://download.pytorch.org/libtorch/nightly/cpu/libtorch-macos-latest.zip and it does not have any I'll also update the docs to emphasize that the |
@goldsborough Thank u, I will have a try. |
@goldsborough I meet the same problem today when I try to use the cpp api in my Macos. What I've done is:
cmake_minimum_required(VERSION 3.12)
project(torch_cpp_api_test)
set(CMAKE_CXX_STANDARD 17)
find_package(Torch REQUIRED)
set(SOURCE_FILES main.cpp)
target_link_libraries(torch_cpp_api_test "${TORCH_LIBRARIES}")
add_executable(torch_cpp_api_test ${SOURCE_FILES})
CMake Error at CMakeLists.txt:6 (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. I really don't know how to do as I'm not very familiar with cmake. New: |
@ganler the libtorch-macos-latest.zip does not contain a library in ./lib, is that ok? |
same problem here, i have CUDA 9 and pytorch running on linux i have the same error when i run this command
my libtorch folder is in the home How to find the TorchConfig.cmake? |
@ganler you need to set |
i set "cmake -DCMAKE_PREFIX_PATH=/path/to/example-app/libtorch/ .." in cmake-options at Clion's settings. |
@Arnold1 this is what the
|
Thanks your guy,I met the same problem and it solved. |
What if you additionally set |
|
@peterjc123 Can you pls advise? |
@oranichu |
Add this in your CMakeLists.txt file before Which should point to where Torch is unzipped appropriately. |
@oke-aditya People might put their libtorch unzipped files in different folders, so it might be better to ask them specify it when doing cmake. |
Can this be added to docs. For people who unzip it in different directory. So that they don't get confused. Like I got. |
@oke-aditya. Yes, we will update our doc with more details on building libtorch, thanks. |
Oh wow, this thread is very helpful to fix my issue. libtorch folder is under ~/Project/ThirdParty/ for me. I am using visual studio code on ubuntu and have this in my CMake file: list(APPEND CMAKE_PREFIX_PATH {PROJECT_SOURCE_DIR}/ThirdParty/libtorch/ However, the above does not work and Torch cannot be found. Following suggestions here, I get the above fixed by using absolute path, instead of {PROJECT_SOURCE_DIR}. |
This I was following the TorchScript guide to use a model in C++ and ran into the same problem as OP. Would be great if this solution could be added to the guide: https://pytorch.org/tutorials/advanced/cpp_export.html#depending-on-libtorch-and-building-the-application |
Update on my previous post: it turns out that the make file can use {PROJECT_SOURCE_DIR}, but there has to be a dollar sign before it: list(APPEND CMAKE_PREFIX_PATH ${PROJECT_SOURCE_DIR}/ThirdParty/libtorch/
|
hello, i found the same problem on the test case. @peterjc123 Is there any solution?:
OS: win10
I found the reason for error: https://discuss.pytorch.org/t/pytorch-c-libs-on-windows-abi-error/42008, libtorch only supports MSVC |
I am getting the same error even after setting the path @goldsborough |
I solved it. You must put the libtorch to your project dir. libtorch can be get in pytorch official website. Then you need to add a sentence to your cmakelists.txt: set(Torch_DIR "libtorch/share/cmake/Torch") The problem can be addressed |
I encountered the same problem, and it simply works for me. |
Solution: export Torch_DIR as env variable before cmake, |
@XiangL-Xr It works for me |
I really don't want to download libtorch, thanks your sovlution.. |
Since the libtorch installation docs are still not updated, can you please enlighten those of us that found your answer with some details?
If I understand correctly, Although your solution works, I have no idea why and I don't think that's a good thing. |
`PS C:\Users\abhis\dev\DASP-CPP\build> cmake -DCMAKE_PREFIX_PATH=C:/Users/abhis/Downloads/libtorch-shared-with-deps-latest/libtorch/ .. CMake Error at C:/Program Files/CMake/share/cmake-3.30/Modules/FindPackageHandleStandardArgs.cmake:233 (message): Seems I'm still facing the same error. |
C++ build documentation seems has code bugs:
Simply following the tutorial of newest libtorch doc, just got errors.
It's cmake issue, I think documentation should more specific and make Torch finable.
cc @yf225 @glaringlee
The text was updated successfully, but these errors were encountered: