PyMesh是一个专注于几何处理的快速平台,是用C++和Python编写的。在C++中实现了计算密集型功能,在Python实现了简洁易用的接口。(本文所有命令皆在终端执行,userName为用户名)
当使用
git clone https://github.com/PyMesh/PyMesh.git
cd PyMesh
git submodule update --init
export PYMESH_PATH=`pwd`
python -m pip install --user -r $PYMESH_PATH/python/requirements.txt
python setup.py build
python setup.py install --user
或者使用
wget https://paddle-org.bj.bcebos.com/paddlescience/PyMesh.tar.gz
tar -zxvf PyMesh.tar.gz
cd PyMesh
export PYMESH_PATH=`pwd`
python -m pip install --user -r $PYMESH_PATH/python/requirements.txt
python setup.py build
python setup.py install --user
方法尝试编译PyMesh时会出现很多报错,毕竟PyMesh发布最新的一版已经是4年前了。
编译时会遇到
(1)第一个错误
Command 'python' not found, did you mean:
command 'python3' from deb python3
command 'python' from deb python-is-python3
执行命令
python3 --version
which python3
确认python版本及解释器的位置。应返回
python 3.10.12
/usr/bin/python3
- 将关于python命令全部改用python3即可。
(2)第一个警告
/usr/lib/python3/dist-packages/setuptools/dist.py:723: UserWarning: Usage of
dash-separated 'description-file' will not be supported in future versions.
Please use the underscore name 'description_file' instead
- 将PyMesh/setup.cfg中的description-file改为description_file即可
(3)第二个错误
running build
/usr/bin/env: ‘python’: No such file or directory
Traceback (most recent call last):
File "/home/userName/PyMesh/setup.py", line 106, in <module>
setup(
...
File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['third_party/build.py', 'cgal']'
returned non-zero exit status 127.
- 错误信息提示 /usr/bin/env: 'python' : No such file or directory,意味着环境变量python指向的路径不存在或python命令不可用。
- 确认存在python解释器后,将PyMesh目录下的setup.py文件首行,PyMesh/scripts目录下的所有.py文件首行以及PyMesh/third_party目录下的build.py文件首行的
#!/usr/bin/env python
改为
#!/usr/bin/env python3
即可。
(4)第三个错误
#include <cstddef>
In file included from
/home/userName/PyMesh/third_party/draco/src/draco/core/hash_utils.cc:15:
/home/userName/PyMesh/third_party/draco/src/draco/core/hash_utils.h:26:1:
error: ‘size_t’ does not name a type
26 | size_t HashCombine(T1 a, T2 b) {
| ^~~~~~
/home/userName/PyMesh/third_party/draco/src/draco/core/hash_utils.h:20:1:
note: ‘size_t’ is defined in header ‘<cstddef>’;
did you forget to ‘#include <cstddef>’?
19 | #include <functional>
+++ |+#include <cstddef>
...
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['third_party/build.py', 'draco']'
returned non-zero exit status 1
- 该错误信息指出在编译draco库时遇到了问题,具体是因为size_t类型未被识别。size_t是 C++ 中的一个用于表示大小的标准类型,在<cstddef>头文件中定义。
- 在PyMesh/third_party/draco/src/draco/core/hash_utils.h头文件顶部加入#include <cstddef> 即可。
(5)第四个错误
/home/userName/PyMesh/third_party/draco/src/draco/io/parser_utils.cc:
In function ‘bool draco::parser::ParseFloat(draco::DecoderBuffer*, float*)’:
/home/userName/PyMesh/third_party/draco/src/draco/io/parser_utils.cc:113:16:
error: ‘numeric_limits’ is not a member of ‘std’
113 | v = std::numeric_limits<double>::infinity();
| ^~~~~~~~~~~~~~
/home/userName/PyMesh/third_party/draco/src/draco/io/parser_utils.cc:113:31:
error: expected primary-expression before ‘double’
113 | v = std::numeric_limits<double>::infinity();
| ^~~~~~
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['third_party/build.py', 'draco']'
returned non-zero exit status 1.
- 这个编译错误指出在编译draco库时遇到了问题,具体错误为 (1) error: 'numeric_limits' is not a memver of 'std'; (2) expected primary-expression before 'double'
- 在PyMesh/third_party/draco/src/draco/io/parser_utils.cc文件顶部加入#include <limits> 即可。
(6)第五个错误
CMake Generate step failed. Build files cannot be regenerated correctly.
Traceback (most recent call last):
File "/home/userName/PyMesh/third_party/build.py", line 82, in <module>
main();
...
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError:
Command '['cmake', '/home/userName/PyMesh/third_party/../third_party/mmg',
'-DBUILD_SHARED_LIBS=Off', '-DCMAKE_POSITION_INDEPENDENT_CODE=On',
'-DCMAKE_INSTALL_PREFIX=/home/userName/PyMesh/third_party/../python/pymesh/third_party/']'
returned non-zero exit status 1.
...
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['third_party/build.py', 'mmg']'
returned non-zero exit status 1.
- 该错误为mmg文件的编译错误。采用以下命令将mmg代码克隆到本地。将PyMesh/third_party中的mmg目录以及所有文件删除,将克隆到本地的代码复制到上述目录内。
git clone https://github.com/MmgTools/mmg.git
重新编译会遇到第六个错误。
(7)第六个错误
/home/userName/PyMesh/tools/Triangulation/MMG/Delaunay.cpp:45:27: error:
too few arguments to function
‘int MMG2D_Set_meshSize(MMG5_pMesh, int32_t, int32_t, int32_t, int32_t)’
45 | if (MMG2D_Set_meshSize(mmgMesh,num_points,0,num_segments) != 1) {
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from
/home/userName/PyMesh/python/pymesh/third_party/include/mmg/libmmg.h:38,
from /home/userName/PyMesh/tools/Triangulation/MMG/Delaunay.cpp:8:
/home/userName/PyMesh/python/pymesh/third_party/include/mmg/mmg2d/libmmg2d.h:357:24:
note: declared here
...
/home/userName/PyMesh/tools/Triangulation/MMG/Delaunay.cpp:85:27: error:
too few arguments to function
‘int MMG2D_Get_meshSize(MMG5_pMesh, int32_t*, int32_t*, int32_t*, int32_t*)’
85 | if (MMG2D_Get_meshSize(mmgMesh,
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~
86 | &num_vertices, &num_triangles, &num_edges) !=1) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from
/home/userName/PyMesh/python/pymesh/third_party/include/mmg/libmmg.h:38,
from /home/userName/PyMesh/tools/Triangulation/MMG/Delaunay.cpp:8:
/home/userName/PyMesh/python/pymesh/third_party/include/mmg/mmg2d/libmmg2d.h:911:24:
note: declared here
...
/home/userName/PyMesh/tools/Triangulation/MMG/Delaunay.cpp:156:27: error:
too few arguments to function
‘int MMG2D_Set_meshSize(MMG5_pMesh, int32_t, int32_t, int32_t, int32_t)’
156 | if (MMG2D_Set_meshSize(mmgMesh,num_input_vertices,num_input_faces,0) != 1) {
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from
/home/userName/PyMesh/python/pymesh/third_party/include/mmg/libmmg.h:38,
from /home/userName/PyMesh/tools/Triangulation/MMG/Delaunay.cpp:8:
/home/userName/PyMesh/python/pymesh/third_party/include/mmg/mmg2d/libmmg2d.h:357:24:
note: declared here
- 该错误是由于MMGD_Set_meshSize和MMG2D_Get_meshSize这两个函数被调用时参数数量不足引起的。在libmmg2d.h中,这两个函数都需要五个参数,但代码中只传入了四个。
- 将PyMesh/tools/Triangulation/MMG目录下的Delauany.cpp的第45行
if (MMG2D_Set_meshSize(mmgMesh,num_points,0,num_segments) != 1)
#改为
if (MMG2D_Set_meshSize(mmgMesh,num_points,0,0,num_segments) != 1)
- 85和86行
if (MMG2D_Get_meshSize(mmgMesh,
&num_vertices, &num_triangles, &num_edges) !=1)
#改为
if (MMG2D_Get_meshSize(mmgMesh,
&num_vertices, &num_triangles, NULL, &num_edges) !=1)
- 156行
if (MMG2D_Set_meshSize(mmgMesh,num_input_vertices,num_input_faces,0) != 1)
#改为
if (MMG2D_Set_meshSize(mmgMesh,num_input_vertices,num_input_faces,0,0) != 1)
- 215和216行
if (MMG2D_Get_meshSize(mmgMesh,
&num_vertices, &num_triangles, &num_edges) !=1)
#改为
if (MMG2D_Get_meshSize(mmgMesh,
&num_vertices, &num_triangles, NULL, &num_edges) !=1)
至此所有错误都解决完毕,应该能全部编译过去了。最后在终端输入命令
python3 setup.py install --user
最后
此时在终端输入以下命令测试是否编译成功
python3 -c "import pymesh; pymesh.test()"
可能会出现警告和错误
DeprecationWarning:
`numpy.distutils` is deprecated since NumPy 1.23.0, as a result
of the deprecation of `distutils` itself. It will be removed for
Python >= 3.12. For older Python versions it will remain present.
It is recommended to use `setuptools < 60.0` for those Python versions.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/userName/.local/lib/python3.10/site-
packages/numpy/testing/_private/nosetester.py", line 461, in test
...
File "/home/userName/.local/lib/python3.10/site-packages/nose/plugins/attrib.py",
line 242, in validateAttrib
if isinstance(value, collections.Callable):
AttributeError: module 'collections' has no attribute 'Callable'
- 在python3中Callable已被移除,取而代之的是collections.abc.Callable。故在终端输入以下命令,将attrib.py,suite.py和case.py文件中的isinstance()函数内的的collections.Callable改为collections.abc.Callable即可
gedit /home/userName/.local/lib/python3.10/site-packages/nose/plugins/attrib.py
gedit /home/userName/.local/lib/python3.10/site-packages/nose/suite.py
gedit /home/userName/.local/lib/python3.10/site-packages/nose/case.py
至此编译全部完成,再输入测试命令会出现
Ran 175 tests in 1.419s
OK (SKIP=2)
编译PyMesh成功。