How to install METIS package in python on windows?

老子叫甜甜 提交于 2019-12-13 20:04:07

问题


I am currently running a source code in python which uses METIS. I wanted to run it using Jetbrains PyCharm, conda interpreter and these are installed on windows 10. Although I have installed METIS using conda, I could not enable shared libraries and I faced this error:

ModuleNotFoundError: No module named 'metis'

When I tried to run it without conda I faced the following error although I have added the metis.dll location to the environment variables.

RuntimeError: Could not load METIS dll

Could anyone please help me about it?


回答1:


This question is old, but I ran into the same problem and after going down the rabbit's hole for.. too long... I have an answer that worked for me.

First, you should get the python metis wrapper using pip: pip install metis.

Second, You must install conda-metis, which you can find here. Although pip calls the metis python wrapper metis, it just the metis wrapper and does not have metis itself.

Place the files in conda-metis-master in some file path.

The installation requires some fixes. Make sure you have a recent version of Visual Studios (I used 2017). For me, VS had a problem running the instructions in BUILD-WINDOWS.txt, which landed me on this thread:

Why does MSBuild look in C:\ for Microsoft.Cpp.Default.props instead of c:\Program Files (x86)\MSBuild? ( error MSB4019)

Specifically, the answer For Visual Studio 2017 and 2019 on Windows 10 was what I went with. Run:

set VCTargetPaths=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets

in command prompt with full permissions to set the environment variable.

Also go to Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ in regedit and change in 4.0 the variable MSBuildOverrideTasksPath and in ToolsVersion\4.0\ the variable MSBuildToolPath to C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin.

For the python metis, we need a .dll, not .lib[1], so we must also look closer at the CMakeLists.txt (see the Linux version of this discussion here). We add on line 19: set(METIS_LIBRARY_TYPE SHARED).

You should follow the BUILD-WINDOWS.txt instructions, but run .\vsgen -G "Visual Studio 15 2017 Win64" inside your conda-metis file path in command prompt with full permissions instead of using Visual Studio 10.

Wait! We need another fix before following the instructions further on using VS to build the the library. Following what was said in:

rint() issue after creating VS Project using CMake

we have to edit the file path_to_your_metis_dir\GKlib\gk_arch.h by removing the line: #define rint(x) ((idx_t)((x)+0.5)). (Or the fix listed on this github exchange.)

Then go to path_to_your_metis_dir\build\windows\.

Open METIS.sln in Visual Studios, go to the top to Build and from the scroll-down go to Build Solution. Afterwards, the .dll file will be in path_to_your_metis_dir\build\windows\libmetis\Release\.

Last, we run in command prompt: set METIS_DLL=path_to_your_metis_dir\build\windows\libmetis\Release\metis.dll

After this, python metis no longer failed on the step from metis import * for me.

[1] If we could use .lib, then conda install -c conda-forge metis would work to get this file, but setting METIS_DLL to the .lib file leads to a windows error.



来源:https://stackoverflow.com/questions/50675790/how-to-install-metis-package-in-python-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!