ModuleNotFoundError: No module named ‘pysat.solvers‘(已解决)

问题

尝试使用以下代码学习pysat的使用,参考

from pysat.solvers import Solver

def solve_sat_from_clauses(clauses):
    '''
    use g3 solver to solve the clauses list
    >>>> Parameters:
    :clauses: clauses that should be satisified
    >>>> Return:
    :solutions: all possible solutions to the sat problem
    '''
    solutions = []
    with Solver(name='g3') as s1:  # define a g3 solver
        for clause in clauses:
            s1.add_clause(clause)  # add clauses
        if s1.solve():
            for solution in s1.enum_models():  # enumerate all possible solutions
                solutions.append(solution)
    return solutions
if __name__ == "__main__":
    c = [[1,-2],[2,-1]]
    # c = [[1, -2], [-1]]
    s = solve_sat_from_clauses(c)
    print(s)

报错

ModuleNotFoundError: No module named 'pysat.solvers'

原因

参考以下内容,但无效
https://github.com/pysathq/pysat/issues/96
原安装方案是pip install pysat,后来发现不应该安装这个,这个pysat的主页是https://pysat.readthedocs.io/en/latest/index.html,其pipi地址为https://pypi.org/project/pysat/

解决方案

pysat.solvers所使用的pysat为https://pysathq.github.io/,安装方式为pip install python-sat,其pipi地址为https://pypi.org/project/python-sat/

你可能感兴趣的:(SAT,python,pip,机器学习,sat,启发式优化)