0

I just coded a quadratic programming and it has worked very well but after the someday it works not at all.

Does anyone have any idea what the problem is?

My code is:

import time
import numpy as np  
from numpy import array, dot
from qpsolvers import solve_qp


Matrix10 = np.load(r'C:\Users\skqkr\Desktop\Semesterarbeit/Chiwan_Q7.npz')
start = time.time()

P = Matrix10['Q']  # quick way to build a symmetric matrix
q = Matrix10['p']
G = Matrix10['G']
h = Matrix10['h']


x = solve_qp(P, q, G, h )>print("QP solution: x = {}".format(x))
print("time :", time.time() - start)

And the result is:

ImportError: cannot import name 'solve_qp' from 'qpsolvers' (C:\Users\skqkr\qpsolvers.py)

I don't understand why it isn't suddenly going well.

NicoE
  • 4,373
  • 3
  • 18
  • 33

1 Answers1

1

I do not think the code you shared is the one you are really using hence it is not easy to understand what is going on. However there are few reason for your problem to happen

The python ImportError: cannot import name error occurs when the import class is inaccessible or the imported class in circular dependence. The import keyword is used to load class and function. The keyword from is used to load the module. For any reason, if the import class is not available in the python class path, The “ImportError: cannot import name” python error is thrown.

The following are the reasons for the ImportError: cannot import name

The import class is not available or not created. The import class name is mis-named or mis-spelled The import class name and module name is mis-placed. The import class is not available in python class path The import class is not available in python library The import class is in circular dependency The python module is just a python file with the .py extension. The keyword from will be used to load the python module. A class in a python module is imported using the keyword import. If the imported class is not in the referred python file, the python interpreter will throw the error ImportError: Cannot import name.

If two python files refer to each other and attempt to load the other file, it will create the circular load dependence. That will cause error in heap memory. If the python interpreter detects the circular dependence, it throws the error ImportError: Can’t Import Name.

Marco_sbt
  • 309
  • 1
  • 12