BachiLi / diffvg

Differentiable Vector Graphics Rasterization
https://people.csail.mit.edu/tzumao/diffvg/
Apache License 2.0
923 stars 155 forks source link

Windows build fail #26

Open WWYiii opened 3 years ago

WWYiii commented 3 years ago

Thanks for your outstanding contribution!

I encountered some errors while installing@BachiLi.

Could you please help me?

Here's the information.Thank you so much!

Building NVCC (Device) object CMakeFiles/diffvg.dir/Release/diffvg_generated_diffvg.cpp.obj diffvg.cpp C:\Users\LENOVO\Desktop\diffvg-master\pybind11\include\pybind11\cast.h(1405): error : too few arguments for template te mplate parameter "Tuple" [C:\Users\LENOVO\Desktop\diffvg-master\build\temp.win-amd64-3.8\Release\diffvg.vcxproj] detected during instantiation of class "pybind11::detail::tuple_caster<Tuple, Ts...> [with Tuple=std::pair, Ts=<T1, T2>]" (1483): here

C:\Users\LENOVO\Desktop\diffvg-master\pybind11\include\pybind11\cast.h(1479): error : too few arguments for template te mplate parameter "Tuple" [C:\Users\LENOVO\Desktop\diffvg-master\build\temp.win-amd64-3.8\Release\diffvg.vcxproj] detected during instantiation of class "pybind11::detail::tuple_caster<Tuple, Ts...> [with Tuple=std::pair, Ts=<T1, T2>]" (1483): here

C:\Users\LENOVO\Desktop\diffvg-master\pybind11\include\pybind11\cast.h(1041): warning : pointless comparison of unsigne d integer with zero [C:\Users\LENOVO\Desktop\diffvg-master\build\temp.win-amd64-3.8\Release\diffvg.vcxproj] detected during: instantiation of "nv_bool pybind11::detail::type_caster<T, std::enable_if_t<, void>>::load( pybind11::handle, nv_bool) [with T=pybind11::detail::intrinsic_t]" (2004): here instantiation of "__nv_bool pybind11::detail::argument_loader::load_impl_sequence(pybind11::deta il::function_call &, std::index_sequence) [with Args=<pybind11::detail::value_and_holder &, size_t>, Is=<0ULL, 1ULL>]" (1980): here instantiation of "__nv_bool pybind11::detail::argument_loader::load_args(pybind11::detail::funct ion_call &) [with Args=<pybind11::detail::value_and_holder &, size_t>]" C:/Users/LENOVO/Desktop/diffvg-master/pybind11/include\pybind11/pybind11.h(159): here instantiation of "void pybind11::cpp_function::initialize(Func &&, Return ()(Args...), const Extra &...) [with Func=lambda [](pybind11::detail::value_and_holder &, size_t)->void, Return=void, Args=<pybind11::detail::value _and_holder &, size_t>, Extra=<pybind11::name, pybind11::is_method, pybind11::sibling, pybind11::detail::is_new_style _constructor>]" C:/Users/LENOVO/Desktop/diffvg-master/pybind11/include\pybind11/pybind11.h(72): here instantiation of "pybind11::cpp_function::cpp_function(Func &&, const Extra &...) [with Func=lambda [](py bind11::detail::value_and_holder &, size_t)->void, Extra=<pybind11::name, pybind11::is_method, pybind11::sibling, pyb ind11::detail::is_new_styleconstructor>, =void]" C:/Users/LENOVO/Desktop/diffvg-master/pybind11/include\pybind11/pybind11.h(1162): here instantiation of "pybind11::class<type, options...> &pybind11::class<type_, options...>::def(const cha r , Func &&, const Extra &...) [with type_=ptr, options=<>, Func=lambda [](pybind11::detail::value_and_holder &, size_t)->void, Extra=]" C:\Users\LENOVO\Desktop\diffvg-master\pybind11\include\pybind11\detail/init.h(176): here instantiation of "void pybind11::detail::initimpl::constructor::execute(Class &, const Extra &.. .) [with Args=, Class=pybind11::class<ptr>, Extra=<>, =0]" C:/Users/LENOVO/Desktop/diffvg-master/pybind11/include\pybind11/pybind11.h(1191): here instantiation of "pybind11::class<type, options...> &pybind11::class<type, options...>::def(const pyb ind11::detail::initimpl::constructor &, const Extra &...) [with type=ptr, options=<>, Args=, Extra=<>]" c:\users\lenovo\desktop\diffvg-master\diffvg.cpp(1655): here

2 errors detected in the compilation of "c:/users/lenovo/desktop/diffvg-master/diffvg.cpp". diffvg.cpp CMake Error at diffvg_generated_diffvg.cpp.obj.Release.cmake:280 (message): Error generating file C:/Users/LENOVO/Desktop/diffvg-master/build/temp.win-amd64-3.8/Release/CMakeFiles/diffvg.dir//Release/diffvg_genera ted_diffvg.cpp.obj

Traceback (most recent call last): File "setup.py", line 91, in setup(name = 'diffvg', File "E:\miniconda\envs\diffvg\lib\site-packages\setuptools__init__.py", line 153, in setup return distutils.core.setup(**attrs) File "E:\miniconda\envs\diffvg\lib\distutils\core.py", line 148, in setup dist.run_commands() File "E:\miniconda\envs\diffvg\lib\distutils\dist.py", line 966, in run_commands self.run_command(cmd) File "E:\miniconda\envs\diffvg\lib\distutils\dist.py", line 985, in run_command cmd_obj.run() File "E:\miniconda\envs\diffvg\lib\site-packages\setuptools\command\install.py", line 67, in run self.do_egg_install() File "E:\miniconda\envs\diffvg\lib\site-packages\setuptools\command\install.py", line 109, in do_egg_install self.run_command('bdist_egg') File "E:\miniconda\envs\diffvg\lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "E:\miniconda\envs\diffvg\lib\distutils\dist.py", line 985, in run_command cmd_obj.run() File "E:\miniconda\envs\diffvg\lib\site-packages\setuptools\command\bdist_egg.py", line 164, in run cmd = self.call_command('install_lib', warn_dir=0) File "E:\miniconda\envs\diffvg\lib\site-packages\setuptools\command\bdist_egg.py", line 150, in call_command self.run_command(cmdname) File "E:\miniconda\envs\diffvg\lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "E:\miniconda\envs\diffvg\lib\distutils\dist.py", line 985, in run_command cmd_obj.run() File "E:\miniconda\envs\diffvg\lib\site-packages\setuptools\command\install_lib.py", line 11, in run self.build() File "E:\miniconda\envs\diffvg\lib\distutils\command\install_lib.py", line 107, in build self.run_command('build_ext') File "E:\miniconda\envs\diffvg\lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "E:\miniconda\envs\diffvg\lib\distutils\dist.py", line 985, in run_command cmd_obj.run() File "setup.py", line 31, in run super().run() File "E:\miniconda\envs\diffvg\lib\site-packages\setuptools\command\build_ext.py", line 79, in run _build_ext.run(self) File "E:\miniconda\envs\diffvg\lib\distutils\command\build_ext.py", line 340, in run self.build_extensions() File "E:\miniconda\envs\diffvg\lib\distutils\command\build_ext.py", line 449, in build_extensions self._build_extensions_serial() File "E:\miniconda\envs\diffvg\lib\distutils\command\build_ext.py", line 474, in _build_extensions_serial self.build_extension(ext) File "setup.py", line 65, in build_extension subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp) File "E:\miniconda\envs\diffvg\lib\subprocess.py", line 364, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--config', 'Release', '--', '/m']' returned non-zero exit status 1.

Dango233 commented 3 years ago

I have exactly the same problem... Any clue?

surjikal commented 2 years ago

I was able to get this to work after trying a bunch of stuff (Windows 10, Visual Studio 2019, Python 3.9).

  1. Apply the patch below in the pybind11 submodule dir
  2. Make sure you have Visual Studio 2019 installed w/ build tools
  3. Make sure you have the python debug libs installed (run the installed, and enable all checkboxes related to debug)
  4. From the diffvg folder, run python setup.py --debug install
  5. Go to the newly installed site package of diffvg, copy the stuff that's in Debug to the parent dir
  6. Rename diffvg to diffvg.pyd

I'd try python setup.py install after step 1, just in case it works for you. Only a Debug build worked for me, for whatever reason.

From b33e16c799992a0486670929eafe19630f171645 Mon Sep 17 00:00:00 2001
From: nick porter <github@surj.email>
Date: Thu, 9 Sep 2021 21:31:50 -0700
Subject: [PATCH] fix windows compilation issue related to type_caster for
 std::pair

---
 include/pybind11/cast.h | 39 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h
index 3e621eba..11b71fe5 100644
--- a/include/pybind11/cast.h
+++ b/include/pybind11/cast.h
@@ -644,8 +644,43 @@ protected:
     Tuple<make_caster<Ts>...> subcasters;
 };

-template <typename T1, typename T2> class type_caster<std::pair<T1, T2>>
-    : public tuple_caster<std::pair, T1, T2> {};
+
+template <typename T1, typename T2> class type_caster<std::pair<T1, T2>> {
+    typedef std::pair<T1, T2> type;
+public:
+    bool load(handle src, bool convert) {
+        if (!isinstance<sequence>(src))
+            return false;
+        const auto seq = reinterpret_borrow<sequence>(src);
+        if (seq.size() != 2)
+            return false;
+        return first.load(seq[0], convert) && second.load(seq[1], convert);
+    }
+
+    static handle cast(const type &src, return_value_policy policy, handle parent) {
+        auto o1 = reinterpret_steal<object>(make_caster<T1>::cast(src.first, policy, parent));
+        auto o2 = reinterpret_steal<object>(make_caster<T2>::cast(src.second, policy, parent));
+        if (!o1 || !o2)
+            return handle();
+        tuple result(2);
+        PyTuple_SET_ITEM(result.ptr(), 0, o1.release().ptr());
+        PyTuple_SET_ITEM(result.ptr(), 1, o2.release().ptr());
+        return result.release();
+    }
+
+    static constexpr auto name = _("Pair");
+
+    template <typename T> using cast_op_type = type;
+
+    operator type() & { return type(cast_op<T1>(first), cast_op<T2>(second)); }
+    operator type() && { return type(cast_op<T1>(std::move(first)), cast_op<T2>(std::move(second))); }
+protected:
+    make_caster<T1> first;
+    make_caster<T2> second;
+};
+
+// template <typename T1, typename T2> class type_caster<std::pair<T1, T2>>
+//     : public tuple_caster<std::pair, T1, T2> {};

 template <typename... Ts> class type_caster<std::tuple<Ts...>>
     : public tuple_caster<std::tuple, Ts...> {};
-- 
2.33.0.windows.2
firebellys commented 2 years ago

This worked for me in VSCode :)

zimonitrome commented 2 years ago

I was not able to use the above fix.

Maybe I am not reading the instructions correctly. What is meant by:

  1. Make sure you have the python debug libs installed (run the installed, and enable all checkboxes related to debug)

I assume that by

  1. From the diffvg folder, run python setup.py --debug install

You actually mean python setup.py build --debug install.

And for

  1. Go to the newly installed site package of diffvg, copy the stuff that's in Debug to the parent dir

I assume that this is a anaconda3/libs/site-packages/diffvg? That folder is never installed for me since python setup.py build --debug install still causes the same error as above, even after applying the patch.

mkiffer commented 1 year ago
  1. Apply the patch below in the pybind11 submodule dir

I am not sure where this code is supposed to go in th pybind11 folder? Am I meant to edit one of the files? TIA @surjikal

mkiffer commented 1 year ago

i have navigated to \diffvg\pybind11> in powershell and copy and pasted the patch from "diff --git..." onwards but get a flurry of errors.

Do I need to change the "a" in a/include/pybind11/cast.h to my local directory?

@surjikal