“from Brightway2 import *”的属性错误

问题描述 投票:0回答:2

当我尝试将brightway2导入jupyter-lab时,出现属性错误,我尝试了多种方法,但问题仍然存在。所以我需要帮助。 要打开 jupyter-lab,我按照以下步骤操作 - 从 anaconda -> 环境 -> Brightway -> 使用终端打开。 然后,我使用终端打开 jupyter-lab。 然后,我尝试通过命令

from brightway2 import *
将 Brightway 导入到 jupyter-lab 中,出现以下属性错误。另外,当我尝试直接通过 anaconda 的终端执行此操作时,我收到相同的错误。我还尝试了不同版本的 numpy 但没有成功。我的 Brightway 和其他一切都已更新。 **我的电脑:** MacBook Pro 2017 - 2.3 GHz 双核 Intel Core i5、Intel Iris Plus 显卡 640 1536 MB、16 GB 2133 MHz LPDDR3、macOS 13.6.1 (22G313) 有没有其他人遇到过这个问题,你是怎么解决的,有推荐的方法吗?我该如何解决这个问题?

错误:


AttributeError                            Traceback (most recent call last)
Cell In[1], line 1
----> 1 from brightway2 import *

File ~/anaconda3/envs/bw/lib/python3.11/site-packages/brightway2/__init__.py:2
      1 # -*- coding: utf-8 -*
----> 2 from bw2data import *
      3 from bw2calc import *
      4 from bw2io import *

File ~/anaconda3/envs/bw/lib/python3.11/site-packages/bw2data/__init__.py:64
     61 config.p = preferences
     63 from .serialization import JsonWrapper
---> 64 from .database import DatabaseChooser as Database, get_activity
     65 from .data_store import DataStore, ProcessedDataStore
     66 from .method import Method

File ~/anaconda3/envs/bw/lib/python3.11/site-packages/bw2data/database.py:6
      3 from eight import *
      5 from . import databases, config
----> 6 from .backends.single_file import SingleFileDatabase
      7 from .backends.json import JSONDatabase
      8 from .backends.peewee import SQLiteBackend

File ~/anaconda3/envs/bw/lib/python3.11/site-packages/bw2data/backends/__init__.py:5
      2 from __future__ import print_function, unicode_literals
      3 from eight import *
----> 5 from .base import LCIBackend
      6 from .peewee import SQLiteBackend
      7 from .json import JSONDatabase

File ~/anaconda3/envs/bw/lib/python3.11/site-packages/bw2data/backends/base.py:12
      3 from eight import *
      5 from .. import (
      6     config,
      7     databases,
   (...)
     10     projects,
     11 )
---> 12 from ..data_store import ProcessedDataStore
     13 from ..errors import UntypedExchange, InvalidExchange, UnknownObject
     14 from ..query import Query

File ~/anaconda3/envs/bw/lib/python3.11/site-packages/bw2data/data_store.py:151
    147         self.validator(data)
    148         return True
--> 151 class ProcessedDataStore(DataStore):
    152     """
    153 Brightway2 data stores that can be processed to NumPy arrays. In addition to ``metadata`` and (optionally) ``validator``, subclasses should define:
    154 
   (...)
    160 
    161     """
    162     dtype_fields = None

File ~/anaconda3/envs/bw/lib/python3.11/site-packages/bw2data/data_store.py:172, in ProcessedDataStore()
    162 dtype_fields = None
    163 # Numpy columns names can't be unicode
    164 base_uncertainty_fields = [
    165     (numpy_string('uncertainty_type'), np.uint8),
    166     (numpy_string('amount'), np.float32),
    167     (numpy_string('loc'), np.float32),
    168     (numpy_string('scale'), np.float32),
    169     (numpy_string('shape'), np.float32),
    170     (numpy_string('minimum'), np.float32),
    171     (numpy_string('maximum'), np.float32),
--> 172     (numpy_string('negative'), np.bool),
    173 ]
    175 @property
    176 def dtype(self):
    177     """Returns both the generic ``base_uncertainty_fields`` plus class-specific ``dtype_fields``. ``dtype`` determines the columns of the :ref:`processed array <processing-data>`."""

File ~/anaconda3/envs/bw/lib/python3.11/site-packages/numpy/__init__.py:324, in __getattr__(attr)
    319     warnings.warn(
    320         f"In the future `np.{attr}` will be defined as the "
    321         "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
    323 if attr in __former_attrs__:
--> 324     raise AttributeError(__former_attrs__[attr])
    326 if attr == 'testing':
    327     import numpy.testing as testing

AttributeError: module 'numpy' has no attribute 'bool'.
`np.bool` was a deprecated alias for the builtin `bool`. To avoid this error in existing code, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  • 此外,当我尝试直接通过终端从 anaconda 执行此操作时,我得到了相同的错误。
  • 我尝试更新所有内容,brightway。
  • 我还在 anaconda 上为 Brightway 创建了另一个环境,并再次打开 jupyter-lab ,并在
    from brightway2 import *
    命令中遇到了相同的错误。
  • 我尝试了不同版本的 numpy,例如 1.19.0 和 1.20.0,但没有成功。
import attributeerror brightway
2个回答
0
投票

此问题已在 commit 0509092 中修复,并于 2023 年 2 月 24 日在 3.6.6 中发布。

在 conda 上,您可以使用以下方式升级:

conda update bw2data"=3.6.6"

0
投票

仅供参考,克里斯的解决方案对我有用,但就我而言,我必须这样做:

conda install -c conda-forge bw2data=3.6.6

希望这有帮助

© www.soinside.com 2019 - 2024. All rights reserved.