本人系统环境为Windows11 21H2
Conda-Metis:https://github.com/menpo/conda-metis
VS2019:https://visualstudio.microsoft.com/zh-hans/vs/older-downloads/
不推荐使用VS2022,本人一开始使用VS2022无法完成cmake项目编译,由于个人水平有限,暂时原因不明
Window+R打开运行,输入regedit,打开注册表,找到\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\路径
1>修改该路径下.\4.0\中的数值数据(MSBuildOverrideTasksPath)为C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin
2>修改该路径下.\ToolVersion\4.0\中的数值数据(MSBuildToolsPath)为C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin
编辑刚刚解压的文件,在根目录下conda-metis-master/CMakeLists.txt,在第19行加入
set(METIS_LIBRARY_TYPE SHARED)
打开conda-metis-master\include\metis.h
将 #define IDXTYPEWIDTH 32 改为#define IDXTYPEWIDTH 64
在conda-metis-master文件夹里进入命令行(cmd)输入下列指令
cmake --help(注意有个空格)
如果能正确运行,应该就能看到一大堆东西,其中就有"Visual Studio 16 2019"等等
.\vsgen -G “Visual Studio 16 2019” -A x64
在运行此代码后,在conda-metis-master\build\windows\下应该会出现很多的文件,如METIS.sln
找到文件conda-metis-master\GKlib\gk_arch.h,编辑
找到并注释: #define rint(x) ((idx_t)((x)+0.5))
使用VS打开conda-metis-master\build\windows\METIS.sln文件,选择Release和x64,然后点击生成(B),再点击生成解决方案(B)
这一步运行可能会报错,不过报错也没关系,可以看看文件夹\conda-metis-master\build\windows\libmetis\Release是否有metis.dll文件,如果有就可以了。
在命令行窗口运行下列代码,这里换回你conda-metis-master的路径前缀。
setx METIS_DLL <‘your path’>\conda-metis-master\build\windows\libmetis\Release\metis.dll
如果发现路径配置不生效,可以考虑把生成的metis.dll文件放入C:\Windows\System32目录下
在命令行窗口输入pip install metis
如果上述步骤都能运行,那应该可以在python里正常引用metis包了
IDXTYPEWIDTH = os.getenv(‘METIS_IDXTYPEWIDTH’, ‘64’)
metis.py位于…\Anaconda3\envs<envs name>\Lib\site-packages\metis.py
本项目在Python下使用Metis初衷是为了运行GitHub项目Cluster-GCN:https://github.com/benedekrozemberczki/ClusterGCN
顺手在这里分享一下运行项目可能遇到的问题:
Memory allocation failed for SetupGraph: adjwgt. Requested size: 15692049316224 bytes
Traceback (most recent call last):
File "D:\Coding\Projects\Python\cluster_gcn\ClusterGCN\src\main.py", line 24, in <module>
main()
File "D:\Coding\Projects\Python\cluster_gcn\ClusterGCN\src\main.py", line 18, in main
clustering_machine.decompose()
File "D:\Coding\Projects\Python\cluster_gcn\ClusterGCN\src\clustering.py", line 38, in decompose
self.metis_clustering()
File "D:\Coding\Projects\Python\cluster_gcn\ClusterGCN\src\clustering.py", line 56, in metis_clustering
(st, parts) = metis.part_graph(self.graph, self.args.cluster_number)
File "D:\Coding\Anaconda3\envs\python39\lib\site-packages\metis.py", line 800, in part_graph
_METIS_PartGraphKway(*args)
File "D:\Coding\Anaconda3\envs\python39\lib\site-packages\metis.py", line 676, in _METIS_PartGraphKway
return _METIS_PartGraphKway.call(nvtxs, ncon, xadj, adjncy, vwgt, vsize,
File "D:\Coding\Anaconda3\envs\python39\lib\site-packages\metis.py", line 501, in _result_errcheck
if result == METIS_ERROR_MEMORY: raise METIS_MemoryError
metis.METIS_MemoryError
Traceback (most recent call last):
File "D:\Coding\Projects\Python\cluster_gcn\ClusterGCN\src\main.py", line 24, in <module>
main()
File "D:\Coding\Projects\Python\cluster_gcn\ClusterGCN\src\main.py", line 18, in main
clustering_machine.decompose()
File "D:\Coding\Projects\Python\cluster_gcn\ClusterGCN\src\clustering.py", line 38, in decompose
self.metis_clustering()
File "D:\Coding\Projects\Python\cluster_gcn\ClusterGCN\src\clustering.py", line 56, in metis_clustering
(st, parts) = metis.part_graph(self.graph, self.args.cluster_number)
File "D:\Coding\Anaconda3\envs\python39\lib\site-packages\metis.py", line 800, in part_graph
_METIS_PartGraphKway(*args)
File "D:\Coding\Anaconda3\envs\python39\lib\site-packages\metis.py", line 676, in _METIS_PartGraphKway
return _METIS_PartGraphKway.call(nvtxs, ncon, xadj, adjncy, vwgt, vsize,
OSError: exception: access violation reading 0x0000026D0AC820C0
以上两问题请注意步骤(3)、(8)、(10)是否成功完成
conda install -c conda-forge pymetis
pip install metis
本人并未尝试此方法安装的PyMetis在Windows能否使用