如何在 Windows 上的 python 中安装 METIS 包? [英] How to install METIS package in python on windows?

查看:177
本文介绍了如何在 Windows 上的 python 中安装 METIS 包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 METIS 的 python 中运行源代码.我想使用 Jetbrains PyCharm、conda 解释器运行它,这些都安装在 Windows 10 上.虽然我使用 conda 安装了 METIS,但我无法启用共享库,我遇到了这个错误:

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: 没有名为metis"的模块

ModuleNotFoundError: No module named 'metis'

当我尝试在没有 conda 的情况下运行它时,我遇到了以下错误,尽管我已将 metis.dll 位置添加到环境变量中.

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.

运行时错误:无法加载 METIS dll

RuntimeError: Could not load METIS dll

有人可以帮我吗?

推荐答案

这个问题很老了,但我遇到了同样的问题,在陷入困境之后......太久了......我有一个有效的答案对我来说.

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.

首先,您应该使用 pip 获取 python metis 包装器:pip install metis.

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

第二,你必须安装 conda-metis,你可以在这里找到.虽然pip调用了metis python包装器metis,但它只是metis包装器,本身并没有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.

将 conda-metis-master 中的文件放在某个文件路径中.

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

安装需要一些修复.确保您拥有最新版本的 Visual Studios(我使用的是 2017).对我来说,VS 在运行 BUILD-WINDOWS.txt 中的指令时遇到了问题,这让我想到了这个线程:

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:

为什么 MSBuild 在 C:\ 中查找 Microsoft.Cpp.Default.props 而不是 c:\Program Files (x86)\MSBuild?(错误 MSB4019)

具体来说,答案对于 Windows 10 上的 Visual Studio 2017 和 2019 是我所采用的.运行:

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.

同时转到注册表编辑器中的 Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ 并在 4.0 中更改变量 MSBuildOverrideTasksPath>ToolsVersion\4.0\ 变量 MSBuildToolPathC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin.

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.

对于python metis,我们需要一个.dll,而不是.lib[1],所以我们还必须仔细查看CMakeLists.txt(请参阅此讨论的 Linux 版本 这里).我们在第 19 行添加:set(METIS_LIBRARY_TYPE SHARED).

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).

您应该按照 BUILD-WINDOWS.txt 说明进行操作,但在命令提示符中的 conda-metis 文件路径中以完全权限运行 .\vsgen -G "Visual Studio 15 2017 Win64" 而不是使用 Visual Studio 10.

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.

等等!在遵循有关使用 VS 构建库的进一步说明之前,我们需要另一个修复程序.遵循以下内容:

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

使用 CMake 创建 VS 项目后的 rint() 问题

我们必须通过删除以下行来编辑文件 path_to_your_metis_dir\GKlib\gk_arch.h:#define rint(x) ((idx_t)((x)+0.5)).(或者在这个github交换上列出的修复.)

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.)

然后转到path_to_your_metis_dir\build\windows\.

在 Visual Studios 中打开 METIS.sln,转到顶部到 Build,然后从向下滚动到 Build Solution.之后,.dll 文件将位于 path_to_your_metis_dir\build\windows\libmetis\Release\.

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\.

最后,我们在命令提示符下运行:set METIS_DLL=path_to_your_metis_dir\build\windows\libmetis\Release\metis.dll

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

在此之后,python metis 在我的 from metis import * 步骤中不再失败.

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

[1] 如果我们可以使用 .lib,那么 conda install -c conda-forge metis 可以获取这个文件,但是设置 METIS_DLL.lib 文件会导致 Windows 错误.

[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.

这篇关于如何在 Windows 上的 python 中安装 METIS 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆