pythoncondacvxpy

Anaconda Python 3.9 (Windows): Why can't CVXPY find qdldl.dll?


I'm running Anaconda Python 3.9 on Windows 10:

Python 3.9.16 (main, Mar  8 2023, 10:39:24) [MSC v.1916 64 bit (AMD64)] on win32

I installed CVXPY in an Anaconda environment using the command:

conda install -c conda-forge cvxpy

I then attempted to run the test suite via

(qutip-env) C:\Users\ray>pytest --pyargs cvxpy.tests

and I obtain

================================================= test session starts =================================================
platform win32 -- Python 3.9.16, pytest-7.1.2, pluggy-1.0.0
rootdir: C:\Users\ray
plugins: rerunfailures-10.1
collecting ... (CVXPY) Apr 05 12:27:19 PM: Encountered unexpected exception importing solver OSQP:
ImportError('DLL load failed while importing qdldl: The specified module could not be found.')
collecting 0 items                                                                                                     (CVXPY) Apr 05 12:27:20 PM: Encountered unexpected exception importing solver OSQP:
ImportError('DLL load failed while importing qdldl: The specified module could not be found.')
collecting 1189 items                                                                                                  (CVXPY) Apr 05 12:27:20 PM: Encountered unexpected exception importing solver OSQP:
ImportError('DLL load failed while importing qdldl: The specified module could not be found.')
collected 1201 items

I assumed that the problem was that the directory containing the DLL qdldl.dll wasn't on my PATH, so I updated my system environment variable to include it:

C:\Users\ray\anaconda3\envs\qutip-env\Library\bin

Closing and restarting the Anaconda prompt, I use

(qutip-env) C:\Users\ray>echo %PATH%

and I see this directory. Python sees it as well if I enter:

(qutip-env) C:\Users\ray>python
Python 3.9.16 (main, Mar  8 2023, 10:39:24) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

>>> import os
>>> print(os.environ['PATH'])

But I see the same "failure to load" error when I test CVXPY again. Is there another way to tell Python/CVXPY where to look for this DLL?

(I actually first saw this problem when trying to import the QuTiP toolbox in a Jupyter notebook, but it's easy to replicate in a command prompt.)


Solution

  • DLL issues frequently arise from channel mixing (Anaconda and Conda Forge are not always compatible, despite Anaconda's blue-sky documentation). Try creating an environment that only uses Conda Forge:

    conda create -n foo -c conda-forge cvxpy
    

    or update everything in the existing environment with Conda Forge prioritized:

    conda update -n qutip-env -c conda-forge --all
    

    (Never do the latter with Anaconda base though.)

    Generally, one should not need to manipulate PATH or LD_LIBRARY_PATH to have a Conda environment work properly. It's usually more a sign of package incompatibilities.