Reputation: 1133
I don't have much knowledge for technical details of installing packages, etc, so this might be a stupid question. I simply first downloaded GLPK and added it to the path, and then tried to install pyglpk through pip install glpk
, which gives the following error messages:
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:\Users\User\Anaconda3\python.exe' 'C:\Users\User\Anaconda3\lib\site-packages\pip\_vendor\pep517\_in_process.py' build_wheel 'C:\Users\User\AppData\Local\Temp\tmpzvxrzwqg':
ERROR: running bdist_wheel
running build
running build_ext
building 'glpk' extension
creating build
creating build\temp.win-amd64-3.7
creating build\temp.win-amd64-3.7\Release
creating build\temp.win-amd64-3.7\Release\src
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.15.26726\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DVERSION_NUMBER="0.4.5" -IC:\Users\User\Anaconda3\include -IC:\Users\User\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.15.26726\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\cppwinrt" /Tcsrc\glpk.c /Fobuild\temp.win-amd64-3.7\Release\src\glpk.obj
glpk.c
c:\users\user\appdata\local\temp\pip-install-m71t9t2y\glpk\src\lp.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
I tried to search for different installation tutorials or questions online, but most of them are for Linux/MacOS, but not for Windows. What can I do about this?
Upvotes: 2
Views: 3733
Reputation: 62037
The answers above give partial clues, but are incomplete.
src\glpk.h
file into your Include
directory. If using Anaconda, this is C:\Users\User\Anaconda3\include
. If using standard Python with a virtual environment, it will be the Include
directory within your virtual environment. If using base Python, C:\Users\<user>\AppData\Local\Programs\Python\Python312\include
.w64
or w32
directory of the unzipped download and copy the glpk_4_65.lib
file (it might be named differently if there is a new version). Paste it into the libs
directory, which will be found in the same level as the include
directory from above. Rename this file glpk.lib
. Create the libs
directory if it does not exist.w64
/w32
, move all of the .dll files (I believe there are four) into C:\Windows\System32
.pip install glpk
import glpk
and test with the simple example from the docs.w64
or w32
folder to C:\Windows\System32
and rename it GLPK
and then add C:\Windows\System32\GLPK
to you path so that you have access to glpsol
from the command line.Upvotes: 0
Reputation: 789
It is looking for glpk.h
in the folder C:\Users\User\Anaconda3\include
. You can make the installation succeed by copying glpk.h
from the GLPK installation into that folder. You will also need to copy glpk.lib
into C:\Users\User\Anaconda3\libs
.
Upvotes: 0
Reputation: 1
I found a solution to run glpk in python without using PIP. I get the same issue and couldn't solve it with PIP.
First thing is download GLPK solver: https://sourceforge.net/projects/winglpk/ GLPK is based in C. You must check where is a file called glpsol.exe And add that directory to the path. look remarked txt in this image
After that you can run your pyomo model and select GLPK as your solver.
Upvotes: 0