coin-or / CyLP

A Python interface to CLP, CBC, and CGL to solve LPs and MIPs.
Other
182 stars 69 forks source link

cylp pip install error windows #176

Closed garnoli99 closed 1 year ago

garnoli99 commented 1 year ago

Hi, running into the error below when trying to install cylp on windows

I searched for similar issues here and saw this issue but the fix involves using python 2.7 and I need python 3.8 for other packages I am using.

Any help would be much appreciated!

         Creating library build\temp.win-amd64-cpython-39\Release\cylp\cpp\CyClpPrimalColumnPivotBase.cp39-win_amd64.lib and object build\temp.win-amd64-cpython-39\Re
lease\cylp\cpp\CyClpPrimalColumnPivotBase.cp39-win_amd64.exp
      IClpPrimalColumnPivotBase.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl ClpPrimalColumnPivot::switchOffSprint(void)" (?switchOff
Sprint@ClpPrimalColumnPivot@@UEAAXXZ)
      IClpPrimalColumnPivotBase.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl ClpPrimalColumnPivot::numberSprintColumns(int &)const " (
?numberSprintColumns@ClpPrimalColumnPivot@@UEBAHAEAH@Z)
      IClpPrimalColumnPivotBase.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl ClpPrimalColumnPivot::~ClpPrimalColumnPivot(void)" (??1ClpPri
malColumnPivot@@UEAA@XZ)
      IClpPrimalColumnPivotBase.obj : error LNK2001: unresolved external symbol "public: __cdecl ClpPrimalColumnPivot::ClpPrimalColumnPivot(void)" (??0ClpPrimalColumn
Pivot@@QEAA@XZ)
      IClpPrimalColumnPivotBase.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl ClpPrimalColumnPivot::clearArrays(void)" (?clearArrays@C
lpPrimalColumnPivot@@UEAAXXZ)
      IClpPrimalColumnPivotBase.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl ClpPrimalColumnPivot::updateWeights(class CoinIndexedVec
tor *)" (?updateWeights@ClpPrimalColumnPivot@@UEAAXPEAVCoinIndexedVector@@@Z)
      build\lib.win-amd64-cpython-39\cylp\cy\CyClpPrimalColumnPivotBase.cp39-win_amd64.pyd : fatal error LNK1120: 6 unresolved externals
      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.35.32215\\bin\\HostX86\\x64\\link.exe' failed with exit 
code 1120
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for cylp
Failed to build cylp
ERROR: Could not build wheels for cylp, which is required to install pyproject.toml-based projects
hashstat commented 1 year ago

Perhaps related to this issue is that there are no wheels for Windows on PyPI for cylp version 0.91.6.

Cufoon commented 1 year ago

Perhaps related to this issue is that there are no wheels for Windows on PyPI for cylp version 0.91.6.

Yeah, you are right! The version 0.91.5 works.

tkralphs commented 1 year ago

Sorry for the delay in responding. Installing from source on Windows should work, but the place to go for recent binaries of Cbc is here: https://github.com/coin-or/Cbc/releases. You may also need to set the COIN_INSTALL_DIR in order for the Cbc libraries to be found and linked properly.

I did not document the build process for Windows because there should be binary wheels available and on Windows, this should "just work." But indeed, it looks like I never built wheels for Windows when 0.91.6 was released. I will do that.

jk1066 commented 1 year ago

Hi @tkralphs, can you clarify what to set the COIN_INSTALL_DIR to and how to do that? I'm running into the same problem, and I've installed clp, coin, and cython, but still can't get cylp to install, with the error:

Cannot open include file: 'ClpPrimalColumnPivot.hpp': No such file or directory, even though I've made that file from: coin-Bcp and placed it in the specified directory. When I try again it gives the same error but it looks in a different directory within \AppData\Local\Temp.

Or if it's easier to just wait for the wheels to be built for Windows, I can do that instead.

tkralphs commented 1 year ago

When you say you built clp, how did you build it? Setting COIN_INSTALL_DIR assumes you built Cbc with coinbrew and that you therefore have an installation directory with subdirectories bin, lib, include, etc. If you don't have that structure, then setting COIN_INSTALL_DIR is probably not going to work.

The easiest immediate solution is just to install version 0.91.5. But if you need 0.91.6, then you can also just grab pre-built binaries here. I guess that just unpacking one of the msvc zip archives and setting COIN_INSTALL_DIR to point to where the archive is unpacked should work. I'll try to find some time to generate some wheels soon.

jk1066 commented 1 year ago

Sorry, yes--I built Cbc with coinbrew, I wasn't sure if I should set COIN_INSTALL_DIR to the coinbrew directory that contains cbc, clp, BuildTools, etc., or just to cbc with the bin, lib, include, etc.--neither of which solve the cylp installation error.

I just installed cylp 0.91.5 though without issue, so it's not really a problem.

tkralphs commented 1 year ago

The other thing that I guess is important is that you need Cbc 2.10, not master. So maybe that is the issue? It really should work if you build the correct version with coinbrew and set COIN_INSTALL_DIR correctly. But since you were able to install 0.91.5, I guess we don't need to debug.

ChrisMLikesMath commented 1 year ago

Hi - I appear to be having a similar issue trying to install cylp. I've re-created it across multiple PCs and python versions.

For example, if I try

conda create -n testenv python==3.11 anaconda pip install cylp==0.91.5

It'll ask me to set COIN_INSTALL_DIR.

Accordingly, I'll grab a release from https://github.com/coin-or/Cbc/releases and drop it in a folder like C:\STUFF\COIN which contains bin, include, lib, share.

I'll run into various compilation issues with MSVC 14 from VS 2019 or 2022 depending on which PC I'm using.

They range from

Collecting cylp==0.91.5 Using cached cylp-0.91.5.tar.gz (171 kB) Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Requirement already satisfied: numpy>=1.5.0 in c:\users\chris\anaconda3\envs\sciptest\lib\site-packages (from cylp==0.91.5) (1.24.3) Requirement already satisfied: scipy>=0.10.0 in c:\users\chris\anaconda3\envs\sciptest\lib\site-packages (from cylp==0.91.5) (1.11.1) Building wheels for collected packages: cylp Building wheel for cylp (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for cylp (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [237 lines of output] running bdist_wheel running build running build_py creating build creating build\lib.win-amd64-cpython-311 creating build\lib.win-amd64-cpython-311\cylp copying cylp__init__.py -> build\lib.win-amd64-cpython-311\cylp creating build\lib.win-amd64-cpython-311\cylp\cy

... running build_ext cythoning cylp\cy\CyClpPrimalColumnPivotBase.pyx to cylp\cy\CyClpPrimalColumnPivotBase.cpp C:\Users\chris\AppData\Local\Temp\pip-build-env-8_92hvwt\overlay\Lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\chris\AppData\Local\Temp\pip-install-5xr10yfd\cylp_b5d75699dbf746b8960571c54b6e1648\cylp\cy\CyClpPrimalColumnPivotBase.pxd tree = Parsing.p_module(s, pxd, full_module_name) warning: cylp\cy\CyCoinIndexedVector.pxd:23:10: cpdef variables will not be supported in Cython 3; currently they are no different from cdef variables warning: cylp\cy\CyCoinPackedMatrix.pxd:28:10: cpdef variables will not be supported in Cython 3; currently they are no different from cdef variables warning: cylp\cy\CyClpSimplex.pxd:307:10: cpdef variables will not be supported in Cython 3; currently they are no different from cdef variables warning: cylp\cy\CyClpSimplex.pxd:308:10: cpdef variables will not be supported in Cython 3; currently they are no different from cdef variables cythoning cylp\cy\CyClpDualRowPivotBase.pyx to cylp\cy\CyClpDualRowPivotBase.cpp C:\Users\chris\AppData\Local\Temp\pip-build-env-8_92hvwt\overlay\Lib\site-packages\Cython\Compiler\Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: C:\Users\chris\AppData\Local\Temp\pip-install-5xr10yfd\cylp_b5d75699dbf746b8960571c54b6e1648\cylp\cy\CyClpDualRowPivotBase.pxd

...

libClp.lib(ClpPrimalColumnPivot.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in IClpPrimalColumnPivotBase.obj Creating library build\temp.win-amd64-cpython-311\Release\cylp\cpp\CyClpPrimalColumnPivotBase.cp311-win_amd64.lib and object build\temp.win-amd64-cpython-311\Release\cylp\cpp\CyClpPrimalColumnPivotBase.cp311-win_amd64.exp LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library build\lib.win-amd64-cpython-311\cylp\cy\CyClpPrimalColumnPivotBase.cp311-win_amd64.pyd : fatal error LNK1319: 1 mismatches detected error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\bin\HostX86\x64\link.exe' failed with exit code 1319 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for cylp Failed to build cylp ERROR: Could not build wheels for cylp, which is required to install pyproject.toml-based projects

if I take a msvc build or other items about missing lib files if using one of the mingw builds.

At some point I was able to successfully install 0.9.0 after unpacking the mingw build in the COIN folder. I'm not sure if that was before I installed MSVC so perhaps anaconda was using some prepackaged compiler before reaching for my Visual Studio compiler.

@jk1066 Did you run into something similar?

tkralphs commented 1 year ago

There currently isn't a wheel for Python 11. If you set up a virtual environment with Python 10, it should "just work" with 0.91.5. I am working on wheels for 0.91.6 and Python 11 as we speak, so hopefully, it will all be working shortly.

tkralphs commented 1 year ago

OK, there are now wheels for 0.91.6 with Pythons up to 3.11. With some cursory testing, it seems to be OK. @ChrisMLikesMath, can you test and if everything is good, close this issue?

ChrisMLikesMath commented 1 year ago

Hi @tkralphs thank you so much for your help!

And yes, your intuition was right. It looks like I'd mislabeled some of my environments and was trying to install in py3.11 virtual environments incorrectly.

After creating a fresh conda environment

conda create -n cylpenv311 python=3.11 anaconda pip install cylp

Now

python

import cylp

works fine!

I tested further by installing cvxpy and was able to solve an integer problem using cvxpy.CBC -- which is made available to cvxpy if cylp is successfully installed.

Looks like it's working great thanks!

PS: @tkralphs I agree the issue should be closed but it's not my original ticket so I don't think I have the option to close it.