git clone https://gitlab.com/ideasman42/blender-mathutils.git
cd blender-mathutils
python setup.py build
python setup.py install
报错:
fatal error: uchar.h: No such file or directory
fatal error: bits/libc-header-start.h: No such file or directory #include <bits/libc-header-start.h>
src/mathutils/mathutils.c: In function 'mathutils_array_hash':
src/mathutils/mathutils.c:79:24: error: incompatible type for argument 1 of '_Py_HashDouble'
79 | y = _Py_HashDouble(NULL, (double)(array[i++]));
| ^~~~
| |
| void *
In file included from /root/miniconda3/envs/spad2/include/python3.9/Python.h:87,
from src/mathutils/mathutils.c:7:
/root/miniconda3/envs/spad2/include/python3.9/pyhash.h:10:38: note: expected 'double' but argument is of type 'void *'
10 | PyAPI_FUNC(Py_hash_t) _Py_HashDouble(double);
分析:
这里是pip使用源代码安装的时候出现了依赖错误,第一个是依赖存在但是没有关联上,第二个是因为这多半是你所编译的项目是在64位机器上生成32位的项目,你需要安装对应的gcc 32位的库。
前两个都属于C++依赖的问题。你可以通过以下这两行代码检查相关的头文件是否在你的机器上。
如果没有安装上,运行第三行的apt get,libc6-dev是解决unicode相关的错误,gcc-multilib 是解决bits库的相关错误。
ls /usr/include/unicode/uchar.h
ls /usr/include/bits/libc-header-start.h
apt-get install libc6-dev gcc-multilib
除了引入安装这两个依赖之外,我们还需要修改blender-mathutils下的setup.py,以便连接到相关的库。在include_dirs=[]下增加两个位置。
# setup.py文件
include_dirs = [
"src/stubs",
"src/blenlib",
"src/makesdna",
"src/makesdna",
"/usr/include/unicode", // 新增
"/usr/include" // 新增
]
第三个问题,blender-mathutils/src/mathutils/mathutils.c 文件中的_Py_HashDouble函数修改为Npy_HashDouble函数,即可解决问题。
ref:https://github.com/numpy/numpy/commit/ad2a73c18dcff95d844c382c94ab7f73b5571cf3
# blender-mathutils/src/mathutils/mathutils.c 文件
# y = _Py_HashDouble(NULL, (double)(array[i++]));
y = Npy_HashDouble(NULL, (double)(array[i++]));
有些地方因机器而异哈,重要的是解决问题的思路哈,
(1)康康提示缺失的头文件存不存在,不存在想办法安装上。
(2)setup.py 上面连接上相关的文件夹