1

I configured my environment to use TDM-gcc as compiler when I want to install packages using pip.

I followed steps that told in this post;

When I try pip install qpsolvers

I get:

    cwd: C:\Users\USER\AppData\Local\Temp\pip-install-lxah5byx\quadprog\
  Complete output (23 lines):
  running bdist_wheel
  running build
  running build_ext
  skipping 'quadprog\quadprog.cpp' Cython extension (up-to-date)
  building 'quadprog' extension
  creating build
  creating build\temp.win-amd64-3.8
  creating build\temp.win-amd64-3.8\Release
  creating build\temp.win-amd64-3.8\Release\quadprog
  C:\TDM-GCC-64\bin\gcc.exe -mdll -O -Wall -Iquadprog -IE:\WPy64-3850\python-3.8.5.amd64\include -IE:\WPy64-3850\python-3.8.5.amd64\include -c quadprog\quadprog.cpp -o build\temp.win-amd64-3.8\Release\quadprog\quadprog.o
  quadprog\quadprog.cpp:280:41: warning: division by zero [-Wdiv-by-zero]
    280 |     enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) };
        |                                       ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  quadprog\quadprog.cpp:280:79: error: division by zero is not a constant expression
    280 |     enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) };
        |                                                                               ^
  quadprog\quadprog.cpp:280:41: error: '(1 / 0)' is not a constant expression
    280 |     enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) };
        |                                       ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  quadprog\quadprog.cpp:280:79: error: enumerator value for '__pyx_check_sizeof_voidp' is not an integer constant
    280 |     enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) };
        |                                                                               ^
  error: command 'C:\\TDM-GCC-64\\bin\\gcc.exe' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for quadprog

I'm not c programmer and have no Idea how to fix this problem, But I find this solution, but I don't know how to apply this solution to work on pip. Any help would be much appreciated.

I use python 3.8.5, and gcc version 9.2.0 (tdm64-1).

1 Answers1

0

I just encountered this issue today, I might be late but I hope I can help someone who also looking for the answer.

As you may notice that the compile error is raised when installing a dependency package called quadprog, we need to manually create a wheel for quadprog and install it before qpsolvers:

  1. download quadprog source code from pypi.
  2. extract source code and open setup.py inside the folder.
extensions = [
    Extension('quadprog', ['quadprog/quadprog.pyx',
                           'quadprog/aind.c', 'quadprog/solve.QP.c',
                           'quadprog/util.c', 'quadprog/dpofa.c',
                           'quadprog/daxpy.c', 'quadprog/ddot.c',
                           'quadprog/dscal.c', 'quadprog/f2c_lite.c'],
             include_dirs=['quadprog'], language='c++', 
             extra_compile_args = ['-DMS_WIN64'])        #<----Add arg in here
]
  1. apply the solution (add compile args -DMS_WIN64) you mentioned in your post in the line shown above.
  2. cd to the extracted folder by cd change/to/folder/path/of/setup.py, and run python setup.py bdist_wheel, the error should be suppressed.
  3. find the dist folder beside setup.py, you should find a file with .whl.
  4. run pip install path/to/whl/file.
  5. finally, run pip install qpsolver.

You should see something like, and qpsolver should be imported without any issue:

C:\Users\nochenon>pip install qpsolvers
Collecting qpsolvers
  Using cached qpsolvers-1.6.1-py3-none-any.whl (23 kB)
Requirement already satisfied: quadprog>=0.1.8 in c:\users\nochenon\appdata\local\programs\python\python39\lib\site-packages (from qpsolvers) (0.1.8)
Requirement already satisfied: Cython in c:\users\nochenon\appdata\local\programs\python\python39\lib\site-packages (from quadprog>=0.1.8->qpsolvers) (3.0a6)
Installing collected packages: qpsolvers
Successfully installed qpsolvers-1.6.1

C:\Users\nochenon>python
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import qpsolvers
>>>
nochenon
  • 326
  • 2
  • 12