在Windows10上安装pyglpk程序包



我对安装软件包等技术细节不太了解,所以这可能是一个愚蠢的问题。我只是先下载GLPK并将其添加到路径中,然后尝试通过pip install glpk安装pyglpk,这会给出以下错误消息:

Collecting glpk
Using cached https://files.pythonhosted.org/packages/74/e0/8676d8d5404a8f9aee298985d21aae67b776476b01583ff1a3e0030e2f51/glpk-0.4.5.tar.gz
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Building wheels for collected packages: glpk
Building wheel for glpk (PEP 517) ... error
ERROR: Complete output from command 'C:UsersUserAnaconda3python.exe' 'C:UsersUserAnaconda3libsite-packagespip_vendorpep517_in_process.py' build_wheel 'C:UsersUserAppDataLocalTemptmpzvxrzwqg':
ERROR: running bdist_wheel
running build
running build_ext
building 'glpk' extension
creating build
creating buildtemp.win-amd64-3.7
creating buildtemp.win-amd64-3.7Release
creating buildtemp.win-amd64-3.7Releasesrc
C:Program Files (x86)Microsoft Visual Studio2017BuildToolsVCToolsMSVC14.15.26726binHostX86x64cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DVERSION_NUMBER="0.4.5" -IC:UsersUserAnaconda3include -IC:UsersUserAnaconda3include "-IC:Program Files (x86)Microsoft Visual Studio2017BuildToolsVCToolsMSVC14.15.26726include" "-IC:Program Files (x86)Windows Kits10include10.0.17134.0ucrt" "-IC:Program Files (x86)Windows Kits10include10.0.17134.0shared" "-IC:Program Files (x86)Windows Kits10include10.0.17134.0um" "-IC:Program Files (x86)Windows Kits10include10.0.17134.0winrt" "-IC:Program Files (x86)Windows Kits10include10.0.17134.0cppwinrt" /Tcsrcglpk.c /Fobuildtemp.win-amd64-3.7Releasesrcglpk.obj
glpk.c
c:usersuserappdatalocaltemppip-install-m71t9t2yglpksrclp.h(24): fatal error C1083: Cannot open include file: 'glpk.h': No such file or directory
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.15.26726\bin\HostX86\x64\cl.exe' failed with exit status 2
----------------------------------------
ERROR: Failed building wheel for glpk
Running setup.py clean for glpk
Failed to build glpk
ERROR: Could not build wheels for glpk which use PEP 517 and cannot be installed directly

我试着在网上搜索不同的安装教程或问题,但它们大多适用于Linux/MacOS,但不适用于Windows。我该怎么办?

我找到了一个在python中运行glpk而不使用PIP的解决方案。我遇到了同样的问题,无法用PIP解决。

第一件事是下载GLPK求解器:https://sourceforge.net/projects/winglpk/GLPK基于C。您必须检查名为glpsol.exe的文件在哪里并将该目录添加到路径中。查看此图像中的注释txt

之后,你可以运行你的pyomo模型,并选择GLPK作为你的求解器。

它正在文件夹C:UsersUserAnaconda3include中查找glpk.h。通过将glpk.h从GLPK安装复制到该文件夹中,可以使安装成功。您还需要将glpk.lib复制到C:UsersUserAnaconda3libs中。

最新更新