The SolverFactory was unable to create the solver “_glpk_shell”

I have developed a processing script in qgis which calls and solves an optimization model. The solver is glpk. However, access to the solver does not seem to work, neither via the relative nor via the absolute path. The solver is recognized via my normal Python environment, but not via QGIS.The glpk folder is available to me as an already installed folder with glpsol.exe. I have not installed it myself. However, it works for my colleague.

Simplified example:

# -*- coding: utf-8 -*-

from qgis.PyQt.QtCore import QCoreApplication
from qgis.core import (QgsProcessing, 
                       QgsProcessingException, 
                       QgsProcessingParameterNumber, 
                       QgsProcessingAlgorithm,
                       QgsProcessingParameterFeatureSink)
from pyomo.environ import ConcreteModel, Var, Objective, Constraint, NonNegativeReals, SolverFactory
import os
import sys
import io

class ExampleProcessingAlgorithm(QgsProcessingAlgorithm):
    OUTPUT = 'OUTPUT'
    limit1 = 'limit1'
    limit2 = 'limit2'

    def tr(self, string):
        return QCoreApplication.translate('Processing', string)

    def createInstance(self):
        return ExampleProcessingAlgorithm()

    def name(self):
        return 'testglpk'

    def displayName(self):
        return self.tr('testglpk')

    def group(self):
        return self.tr('test')

    def groupId(self):
        return 'test'

    def shortHelpString(self):
        return self.tr("Example algorithm short description")

    def initAlgorithm(self, config=None):
        # parameter
        self.addParameter(
            QgsProcessingParameterNumber(
                'limit1',
                self.tr('limit1'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0,
                defaultValue=8
            )
        )
        self.addParameter(
            QgsProcessingParameterNumber(
                'limit2',
                self.tr('limit2'),
                type=QgsProcessingParameterNumber.Double,
                minValue=0,
                defaultValue=8
            )
        )

        ## results
        self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Output layer')))

    def processAlgorithm(self, parameters, context, feedback):
        # parameter
        limit1 = self.parameterAsDouble(parameters, self.limit1, context)
        limit2 = self.parameterAsDouble(parameters, self.limit2, context)

        # Pyomo-model
        model = ConcreteModel()
        model.x = Var(domain=NonNegativeReals)
        model.y = Var(domain=NonNegativeReals)
        model.cost = Objective(expr=3*model.x + 4*model.y, sense=1)
        model.constr1 = Constraint(expr=2*model.x + model.y >= limit1)
        model.constr2 = Constraint(expr=model.x + 2*model.y >= limit2)

        opt = SolverFactory('glpk')

        # Umleitung von stdout und stderr
        old_stdout = sys.stdout
        old_stderr = sys.stderr
        sys.stdout = io.StringIO()
        sys.stderr = io.StringIO()

        try:
            results = opt.solve(model)
        finally:
            output = sys.stdout.getvalue()
            error_output = sys.stderr.getvalue()
            sys.stdout = old_stdout
            sys.stderr = old_stderr

        feedback.pushInfo("Solution:")
        feedback.pushInfo(f"x = {model.x()}")
        feedback.pushInfo(f"y = {model.y()}")
        feedback.pushInfo(f"Kosten = {model.cost()}")

        feedback.pushInfo("Solver-Output:")
        feedback.pushInfo(output)
        if error_output:
            feedback.pushInfo("Solver-Error-Output:")
            feedback.pushInfo(error_output)

        return {}

The error code is as follows:
RuntimeError: Attempt to use an unavailable solver.
The SolverFactory was not able to create the solver “_glpk_shell” and returned an UnknownSolver object.
and returned an UnknownSolver object. This error is triggered at the point
where the UnknownSolver object was used as if it were valid (by calling the
method “solve”).
The original solver was created with the following parameters
Executable: C:UsersxxxAppDataRoamingPythonPython39site-packagesglpk-5.0Librarybin
Type: _glpk_shell
args: ()
options: {}

Execution failed after 28.03 seconds

I have tried the call with absolute path. I have tried to move glpsol to other folders. Both did not help.

New contributor

user25433359 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật