{"id":23436,"library":"cobra","title":"COBRApy","description":"COBRApy (0.31.1) is a Python package for constraint-based modeling of metabolic networks. It enables building, simulating, and analyzing genome-scale metabolic models using flux balance analysis (FBA) and related methods. Releases occur several times a year, with a focus on stability and new features.","status":"active","version":"0.31.1","language":"python","source_language":"en","source_url":"https://github.com/opencobra/cobrapy","tags":["metabolic modeling","constraint-based modeling","fba","systems biology"],"install":[{"cmd":"pip install cobra","lang":"bash","label":"Install from PyPI"},{"cmd":"pip install cobra[optlang]","lang":"bash","label":"Install with default solver (optlang)"}],"dependencies":[{"reason":"Default LP solver interface (GLPK, CPLEX, Gurobi). Optional but recommended.","package":"optlang","optional":true},{"reason":"Required for DataFrame-based results and model I/O.","package":"pandas","optional":false},{"reason":"Required for SBML file support.","package":"libsbml","optional":true}],"imports":[{"note":"cobra.core provides internals; public API is from cobra.","wrong":"from cobra.core import Model","symbol":"Model","correct":"from cobra import Model"},{"note":"Public API from cobra top-level.","wrong":"from cobra.core import Reaction","symbol":"Reaction","correct":"from cobra import Reaction"},{"note":"Top-level import is correct.","wrong":"from cobra.core import Metabolite","symbol":"Metabolite","correct":"from cobra import Metabolite"},{"note":"Use flux_analysis.pfba, flux_analysis.single_gene_deletion, etc.","wrong":"from cobra.flux_analysis import pfba","symbol":"flux_analysis","correct":"from cobra import flux_analysis"}],"quickstart":{"code":"from cobra import Model, Reaction, Metabolite\nmodel = Model('example')\n# Add reaction: A -> B\nreaction = Reaction('R1')\nreaction.name = 'A to B'\nreaction.subsystem = 'Exchange'\nreaction.lower_bound = 0.  # irreversible\nreaction.upper_bound = 1000.\nmetabolite_a = Metabolite('A_c', compartment='c')\nmetabolite_b = Metabolite('B_c', compartment='c')\nreaction.add_metabolites({metabolite_a: -1, metabolite_b: 1})\nmodel.add_reactions([reaction])\nmodel.objective = 'R1'  # maximize flux through R1\nsolution = model.optimize()\nprint(solution.objective_value)","lang":"python","description":"Create a simple model, add a reaction, set objective, and solve using FBA."},"warnings":[{"fix":"Install cobra[optlang] and use optlang.glpk_interface (or other solver interfaces).","message":"In cobra 0.31, the default solver interface changed to optlang. If you rely on the older glpk interface directly, your code may break.","severity":"breaking","affected_versions":">=0.31"},{"fix":"Use model.objective = {reaction: 1} or reaction.objective_coefficient = 1 for a single reaction.","message":"Setting model.objective = reaction_object does not automatically change the objective coefficient; you must set coefficient explicitly via model.objective = {reaction: 1} or reaction.objective_coefficient = 1.","severity":"gotcha","affected_versions":"all"},{"fix":"Replace cobra.io.sbml.write_sbml with cobra.io.write_sbml_model.","message":"The method 'cobra.io.sbml.write_sbml' is deprecated; use 'cobra.io.write_sbml_model' instead.","severity":"deprecated","affected_versions":">=0.30"},{"fix":"Use solution.fluxes['REACTION_ID'] instead of solution['REACTION_ID'].","message":"Flux balance analysis results are stored in cobra.Solution which is not subscriptable; use solution.fluxes (pandas Series) to access individual fluxes.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'pip install cobra' in your terminal.","cause":"cobra is not installed or virtual environment not activated.","error":"ModuleNotFoundError: No module named 'cobra'"},{"fix":"Use model.objective = 'R1' for a single reaction or model.objective = {'R1': 1, 'R2': 0.5} for multiple.","cause":"Setting model.objective = ['R1', 'R2'] incorrectly (list instead of dict or single reaction).","error":"ValueError: objective must be a scalar (reaction) or dict of reactions to coefficients"},{"fix":"Install optlang: 'pip install cobra[optlang]' or install a solver like GLPK.","cause":"optlang not installed and no solver (e.g., GLPK, CPLEX) available.","error":"No solver interface found"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}