brightway-lca / brightway2-calc

The calculation engine for the Brightway2 life cycle assessment framework.
BSD 3-Clause "New" or "Revised" License
12 stars 15 forks source link

import brightway database error #46

Closed bthnkrts closed 2 years ago

bthnkrts commented 2 years ago

Hello everyone, Recently I am struggling with a problem of brightway import. I am performing an LCA project for my master thesis and it is stuck. Since yesterday, python/jupyternotebook is giving the following problem. I need to find a solution asap. Is there anyone who can help me? Any advice or answer would be awesome helpful.

Thank u!

### Input import brightway2 as bw import os
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt

### Output

ImportError Traceback (most recent call last) File ~\anaconda3\envs\MG\lib\site-packages\bw2data\serialization.py:242, in PickledDict.deserialize(self) 241 try: --> 242 return self.unpack(pickle.load(open(self.filepath, "rb"))) 243 except ImportError:

File ~\anaconda3\envs\MG\lib\site-packages\bw2data\backends__init__.py:5, in 3 from eight import * ----> 5 from .base import LCIBackend 6 from .peewee import SQLiteBackend

File ~\anaconda3\envs\MG\lib\site-packages\bw2data\backends\base.py:5, in 3 from eight import * ----> 5 from .. import ( 6 config, 7 databases, 8 geomapping, 9 mapping, 10 projects, 11 ) 12 from ..data_store import ProcessedDataStore

**ImportError: cannot import name 'databases' from partially initialized module 'bw2data' (most likely due to a circular import) (C:\Users\cansu\anaconda3\envs\MG\lib\site-packages\bw2data__init__.py)

During handling of the above exception, another exception occurred:**

PickleError Traceback (most recent call last) Input In [1], in <cell line: 1>() ----> 1 import brightway2 as bw 2 import os # to use "operating system dependent functionality" 3 import numpy as np # "the fundamental package for scientific computing with Python"

File ~\anaconda3\envs\MG\lib\site-packages\brightway2__init__.py:2, in 1 # -- coding: utf-8 - ----> 2 from bw2data import 3 from bw2calc import 4 from bw2io import *

File ~\anaconda3\envs\MG\lib\site-packages\bw2data__init__.py:35, in 33 from .project import projects 34 from .utils import set_data_dir ---> 35 from .meta import ( 36 dynamic_calculation_setups, 37 calculation_setups, 38 databases, 39 geomapping, 40 mapping, 41 methods, 42 normalizations, 43 preferences, 44 weightings, 45 ) 47 # Add metadata class instances to global list of serialized metadata 48 config.metadata.extend([ 49 dynamic_calculation_setups, 50 calculation_setups, (...) 57 weightings, 58 ])

File ~\anaconda3\envs\MG\lib\site-packages\bw2data\meta.py:192, in 190 preferences = Preferences() 191 weightings = WeightingMeta() --> 192 calculation_setups = CalculationSetups() 193 dynamic_calculation_setups = DynamicCalculationSetups()

File ~\anaconda3\envs\MG\lib\site-packages\bw2data\serialization.py:123, in SerializedDict.init(self, dirpath) 118 raise NotImplemented("SerializedDict must be subclassed, and the filename must be set.") 119 self.filepath = os.path.join( 120 dirpath or projects.dir, 121 self.filename 122 ) --> 123 self.load()

File ~\anaconda3\envs\MG\lib\site-packages\bw2data\serialization.py:128, in SerializedDict.load(self) 126 """Load the serialized data. Creates the file if not yet present.""" 127 try: --> 128 self.data = self.deserialize() 129 except IOError: 130 # Create if not present 131 self.data = {}

File ~\anaconda3\envs\MG\lib\site-packages\bw2data\serialization.py:245, in PickledDict.deserialize(self) 243 except ImportError: 244 TEXT = "Pickle deserialization error in file '%s'" % self.filepath --> 245 raise PickleError(TEXT)

PickleError: Pickle deserialization error in file 'C:\Users\cansu\AppData\Local\pylca\Brightway3\default.c21f969b5f03d33d43e04f8f136e7682\setups.pickle'

haasad commented 2 years ago

You could try to make a backup copy of the C:\Users\cansu\AppData\Local\pylca\Brightway3\default.c21f969b5f03d33d43e04f8f136e7682\setups.pickle and then delete it.

When I google your error message: cannot import name 'databases' from partially initialized module 'bw2data', the very first result is the following stackoverflow thread that suggests the same: https://stackoverflow.com/questions/60542566/cannot-anymore-import-brightway2-importerror

One other thing you could check if there's any files in your directory that could cause import errors, for example if you have a file called databases.py this could produce a circular import error like mentioned in the error message.

bthnkrts commented 2 years ago

Thanks for the answer! If I delete the file from C as you recommend as well, the problem is solved. I need this for my thesis and it was a great help. Thanks again!