You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

创建LCA对象后调用lca.lci()出现Brightway2 OSError求助

Brightway2 LCI计算时出现OSError(访问冲突)问题求助

近期学习Brightway2,遵循《Brightway2初学者速查表》及GitHub入门教程,可完成教程内容,但计算单个活动与方法的LCIA结果时触发OSError,代码如下:

import brightway2 as bw
bw.projects.set_current("test_bw")

ei = bw.Database('ecoinvent-3.9-cutoff')
m = bw.methods

activity = ei.random()
lcia_method = m.random()

lca = bw.LCA({activity: 1}, lcia_method)
lca.lci()

运行lca.lci()时出现以下错误,查阅函数文档未找到原因:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Cell In[49], line 1
----> 1 lca.lci()

File [~\anaconda3\envs\bw\Lib\site-packages\bw2calc\lca.py:342](http://localhost:8888/lab/tree/notebooks/~/anaconda3/envs/bw/Lib/site-packages/bw2calc/lca.py#line=341), in LCA.lci(self, factorize, builder)
    340 if factorize:
    341     self.decompose_technosphere()
--> 342 self.lci_calculation()

File [~\anaconda3\envs\bw\Lib\site-packages\bw2calc\lca.py:350](http://localhost:8888/lab/tree/notebooks/~/anaconda3/envs/bw/Lib/site-packages/bw2calc/lca.py#line=349), in LCA.lci_calculation(self)
    344 def lci_calculation(self):
    345     """The actual LCI calculation.
    346 
    347     Separated from ``lci`` to be reusable in cases where the matrices are already built, e.g. ``redo_lci`` and Monte Carlo classes.
    348 
    349     """
--> 350     self.supply_array = self.solve_linear_system()
    351     # Turn 1-d array into diagonal matrix
    352     count = len(self.activity_dict)

File [~\anaconda3\envs\bw\Lib\site-packages\bw2calc\lca.py:316](http://localhost:8888/lab/tree/notebooks/~/anaconda3/envs/bw/Lib/site-packages/bw2calc/lca.py#line=315), in LCA.solve_linear_system(self)
    314     return self.solver(self.demand_array)
    315 else:
--> 316     return spsolve(
    317         self.technosphere_matrix,
    318         self.demand_array)

File [~\anaconda3\envs\bw\Lib\site-packages\pypardiso\scipy_aliases.py:48](http://localhost:8888/lab/tree/notebooks/~/anaconda3/envs/bw/Lib/site-packages/pypardiso/scipy_aliases.py#line=47), in spsolve(A, b, factorize, squeeze, solver, *args, **kwargs)
     45 if factorize and not solver._is_already_factorized(A):
     46     solver.factorize(A)
--> 48 x = solver.solve(A, b)
     50 if squeeze:
     51     return x.squeeze()  # scipy spsolve always returns vectors with shape (n,) indstead of (n,1)

File [~\anaconda3\envs\bw\Lib\site-packages\pypardiso\pardiso_wrapper.py:188](http://localhost:8888/lab/tree/notebooks/~/anaconda3/envs/bw/Lib/site-packages/pypardiso/pardiso_wrapper.py#line=187), in PyPardisoSolver.solve(self, A, b)
    185 else:
    186     self.set_phase(13)
--> 188 x = self._call_pardiso(A, b)
    190 # it is possible to call the solver with empty columns, but computationally expensive to check this
    191 # beforehand, therefore only the result is checked for infinite elements.
    192 # if not np.isfinite(x).all():
    193 #    warnings.warn('The result contains infinite elements. Make sure that matrix A contains no empty columns.',
    194 #                  PyPardisoWarning)
    195 # --> this check doesn't work consistently, maybe add an advanced input check method for A
    197 return x

File [~\anaconda3\envs\bw\Lib\site-packages\pypardiso\pardiso_wrapper.py:277](http://localhost:8888/lab/tree/notebooks/~/anaconda3/envs/bw/Lib/site-packages/pypardiso/pardiso_wrapper.py#line=276), in PyPardisoSolver._call_pardiso(self, A, b)
    274 ia = A.indptr + 1
    275 ja = A.indices + 1
--> 277 self._mkl_pardiso(self.pt.ctypes.data_as(ctypes.POINTER(self._pt_type[0])),  # pt
    278                   ctypes.byref(ctypes.c_int32(1)),  # maxfct
    279                   ctypes.byref(ctypes.c_int32(1)),  # mnum
    280                   ctypes.byref(ctypes.c_int32(self.mtype)),  # mtype -> 11 for real-nonsymetric
    281                   ctypes.byref(ctypes.c_int32(self.phase)),  # phase -> 13
    282                   ctypes.byref(ctypes.c_int32(A.shape[0])),  # N -> number of equations/size of matrix
    283                   A.data.ctypes.data_as(c_float64_p),  # A -> non-zero entries in matrix
    284                   ia.ctypes.data_as(c_int32_p),  # ia -> csr-indptr
    285                   ja.ctypes.data_as(c_int32_p),  # ja -> csr-indices
    286                   self.perm.ctypes.data_as(c_int32_p),  # perm -> empty
    287                   ctypes.byref(ctypes.c_int32(1 if b.ndim == 1 else b.shape[1])),  # nrhs
    288                   self.iparm.ctypes.data_as(c_int32_p),  # iparm-array
    289                   ctypes.byref(ctypes.c_int32(self.msglvl)),  # msg-level -> 1: statistical info is printed
    290                   b.ctypes.data_as(c_float64_p),  # b -> right-hand side vector/matrix
    291                   x.ctypes.data_as(c_float64_p),  # x -> output
    292                   ctypes.byref(pardiso_error))  # pardiso error
    294 if pardiso_error.value != 0:
    295     raise PyPardisoError(pardiso_error.value)

OSError: exception: access violation writing 0x0000000000000004

已尝试以下方法但未解决问题:

  • 使用包含旧版ecoinvent的其他项目
  • 更新Brightway
  • 切换内核至Python 3.8

恳请提供技术帮助!

内容的提问来源于stack exchange,提问作者Carlos Hernandez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 16:09:52