Search code examples
pythonpipcvxopt

cvxopt with Python3 on MacOS


Importing the cvxopt package isn't working after installing it with pip:

% sw_vers
ProductName:    Mac OS X
ProductVersion: 10.15.7
BuildVersion:   19H15
% python3 --version
Python 3.7.2
% pip3 install cvxopt 
Collecting cvxopt
  Using cached cvxopt-1.2.6-cp38-cp38-macosx_10_9_x86_64.whl (3.1 MB)
Installing collected packages: cvxopt
Successfully installed cvxopt-1.2.6
% cat testcvxopt.py 
import cvxopt

print("hi")
% python3 testcvxopt.py 
Traceback (most recent call last):
  File "testcvxopt.py", line 1, in <module>
    import cvxopt
ModuleNotFoundError: No module named 'cvxopt'

I have read and tried most things I could find about installing cvxopt but haven't found anything that works. Any suggestions? Thanks


Solution

  • % python3 --version
    Python 3.7.2
    % pip3 install cvxopt 
    Collecting cvxopt
      Using cached cvxopt-1.2.6-cp38-cp38-macosx_10_9_x86_64.whl (3.1 MB)
    

    Your default python3 is 3.7 but pip3 runs under Python 3.8. Choose which Python you gonna use and use the one.

    Either run

    python3.7 -m pip install cvxopt
    

    and then use python3.7 to run scripts.

    Or use python3.8 the same way.