patrikhuber / eos

A lightweight 3D Morphable Face Model library in modern C++
Apache License 2.0
1.91k stars 597 forks source link

Python bindings: "ImportError: arg(): could not convert default argument into a Python object [...]" #256

Open barhilleli opened 5 years ago

barhilleli commented 5 years ago

Hi, I have the following problem with using eos-py. After successfully installing eos-py with: pip install eos-py

I get the following error while trying to import the eos library (inside python):

import eos Traceback (most recent call last): File "", line 1, in ImportError: arg(): could not convert default argument into a Python object (type not registered yet?). Compile in debug mode for more information.

I would appreciate your help

patrikhuber commented 5 years ago

Hi,

Hmm, I remember getting this exact error a few weeks ago with a different module, actually. I don't remember what the solution was though, but I do remember that I think it had nothing to do with the code itself. It was perhaps an issue with caching, the compiler, Python versions, something like that. I think after I cleared all build caches and did a clean Release/RelWithDebInfo build, it worked fine again.

I don't think this has anything to do with eos specifically. I think you'll just need to play around a bit with the compilation process, start from a clean build directory, perhaps try a different (64-bit) Python version, perhaps clone eos from GitHub and try installing from there. Perhaps even follow the suggestion in the error message, compile in debug mode, and see what happens.

Sorry that I don't remember more or can't be of more direct help. If you find out more, please let us know here.

barhilleli commented 5 years ago

Thanks for the quick response Patrik, I will try playing some more with the installation process as you suggested.

Thanks again for sharing this awesome package

huntkao commented 5 years ago

I get the error too. I compiled in debug mode and tried to import the eos library (inside python): import eos Traceback (most recent call last): File "", line 1, in ImportError: arg(): could not convert default argument 'vertex_definitions: akrzemi1::nullopt_t' in method '<class 'eos.morphablemodel.MorphableModel'>.init' into a Python object (type not registered yet?)

I need your kind help. Thank you so much.

huntkao commented 5 years ago

I change my default g++/gcc version to g++-7/gcc-7 and rebuild it. The import works fine now.

patrikhuber commented 5 years ago

@huntkao Interesting! What was the previous gcc version that you used that didn't work?

Another idea I had was to completely remove the build directory, and then rebuild with CMAKE_CXX_STANDARD=17. This is/should be the default actually, but since in your error it mentions akrzemi1::nullopt_t, it looks like something has gone wrong with the build and it's using C++14 fallback types.

I remember now that I think I got this error in a similar scenario, and it also went away once I used a clean build directory, made sure CMAKE_CXX_STANDARD is on 17, and used a recent compiler.

@barhilleli, this should also help you.

huntkao commented 5 years ago

My previous gcc version was gcc-6 (6.5.0 actually). When I changed to gcc-7 and rebuilt, I left *CXX_FLAGS as its default values.

Thanks for your quick response.

patrikhuber commented 5 years ago

@huntkao Thanks! It is indeed still a bit of a mystery. But I think if one makes sure to have a clean build directory and to build with CMAKE_CXX_STANDARD=17 (which is/should be the default), then it works (and should also work with gcc-6, unless there's some regression on that compiler).

BenjBarral commented 5 years ago

Hi,

Does anybody have more update on this ? I have the exact same issue. I tried all the solutions listed, no success..

Thank you

patrikhuber commented 5 years ago

Anyone encountering this, please specify more information, otherwise it's not helpful. At the very least:

BenjBarral commented 5 years ago

Hi,

Many thanks

patrikhuber commented 5 years ago

Hi @BenjBarral,

Okay, I think on macOS/XCode, you will need to make sure that the #if here (and the same in eos/cpp17/variant.hpp) is adjusted, so XCode/AppleClang chooses the C++17 branch. Is __cplusplus not >= 201703L in your AppleClang version? Which XCode version are you using?

If you self-compile, also make sure to do a Release build (I think CMake defaults to Debug but it depends on the generator). You can also do pip install .\eos to install from your local/potentially modified sources.

In any case just make sure it uses the C++17 branch in those files and it should be okay. I hope XCode by now supports these C++17 features (it still didn't fully half a year or a year ago). If in doubt, make sure you got the very latest XCode version.

BenjBarral commented 5 years ago

Hi Patrik,

Thanks a lot, this was indeed the problem. Xcode 9 (and AppleClang9) do not fully support C++17. Updating to Xcode 10 solved the problem.

Thanks again !

Benjamin

vineethbabu commented 5 years ago

Hi @patrikhuber i am able to pip install but not able to import it.

My system info: **- Ubuntu 16.4, 64 bit

the error persists, could you please tell me what other things should be checked. Thanks in advance.

patrikhuber commented 5 years ago

Hey @BenjBarral, aah great! That's fantastic, and I'm sure it'll help other people as well! Thanks.

@vineethbabu, if you get any error with akrzemi1::optional or mpark::variant when doing import eos in Python, then you haven't compiled with C++17/CMAKE_CXX_STANDARD 17.

vineethbabu commented 5 years ago

Thank you @patrikhuber for your super quick reply. I changed my default gcc version to gcc 7.4 and installed a newer version of python, now the error is gone.

could you please tell me if there is a way to obtain .obj, mesh and texture from the python code?. Thanks in advance.

patrikhuber commented 5 years ago

@vineethbabu Great!

For your question, this is very off-topic here. Please have a look at demo.py, the documentation, play around with it and learn, and you'll find out.