ecoinvent 3.5 import error: MaybeEncodingError: - python

I was trying to import ecoinvent 3.5 cutoff to a project using brightway, with the following:
if 'ecoinvent 3.5 cutoff' not in databases:
ei35cutofflink=r"H:\Data\ecoinvent 3.5_cutoff_lci_ecoSpold02\datasets"
ei35cutoff=SingleOutputEcospold2Importer(ei35cutofflink, 'ecoinvent 3.5 cutoff')
ei35cutoff.apply_strategies()
ei35cutoff.statistics()
ei35cutoff.write_database()
But I got the following error. It looks like the issue is not that related to brightway, but rather multiprocessing or pickle? I don't understand what the error message means.
---------------------------------------------------------------------------
MaybeEncodingError Traceback (most recent call last)
<ipython-input-4-f9acb2bc0c84> in <module>
1 if 'ecoinvent 3.5 cutoff' not in databases:
2 ei35cutofflink=r"H:\Data\ecoinvent 3.5_cutoff_lci_ecoSpold02\datasets"
----> 3 ei35cutoff=SingleOutputEcospold2Importer(ei35cutofflink, 'ecoinvent 3.5 cutoff')
4 ei35cutoff.apply_strategies()
5 ei35cutoff.statistics()
C:\miniconda3_py37\envs\ab\lib\site-packages\bw2io\importers\ecospold2.py in __init__(self, dirpath, db_name, extractor, use_mp, signal)
63 start = time()
64 try:
---> 65 self.data = extractor.extract(dirpath, db_name, use_mp=use_mp)
66 except RuntimeError as e:
67 raise MultiprocessingError('Multiprocessing error; re-run using `use_mp=False`'
C:\miniconda3_py37\envs\ab\lib\site-packages\bw2io\extractors\ecospold2.py in extract(cls, dirpath, db_name, use_mp)
91 ) for x in filelist
92 ]
---> 93 data = [p.get() for p in results]
94 else:
95 pbar = pyprind.ProgBar(len(filelist), title="Extracting ecospold2 files:", monitor=True)
C:\miniconda3_py37\envs\ab\lib\site-packages\bw2io\extractors\ecospold2.py in <listcomp>(.0)
91 ) for x in filelist
92 ]
---> 93 data = [p.get() for p in results]
94 else:
95 pbar = pyprind.ProgBar(len(filelist), title="Extracting ecospold2 files:", monitor=True)
C:\miniconda3_py37\envs\ab\lib\multiprocessing\pool.py in get(self, timeout)
655 return self._value
656 else:
--> 657 raise self._value
658
659 def _set(self, i, obj):
MaybeEncodingError: Error sending result: '<multiprocessing.pool.ExceptionWithTraceback object at 0x000001D257C55358>'. Reason: 'TypeError("can't pickle lxml.etree._ListErrorLog objects")'```

Use can use use_mp=False to get a sense of what the actual error is (instead of the error not being pickle-able, and this raising a separate errror). In this case I think you have a problem with the data folder, which you can solve by deleting it and downloading or extracting it again.

Related

Getting "AttributeError: 'NoneType' object has no attribute 'groupdict'" when executing an Excel file in Python using the Formulas library

My problem is to save data into an excel file and then make it run its calculations and then read it using python without having to open it. For this I have tried using the formulas library. It worked perfectly fine on a test excel sheet that I tries that had a few calculations. However when I try it on a larger excel sheet with a lot more and complex calculations I get this error message.
AttributeError: 'NoneType' object has no attribute 'groupdict
I will also post the entire error message here:
AttributeError: 'NoneType' object has no attribute 'groupdict'
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_113/60233469.py in <module>
1 fpath = 'MTOOutput.xlsx'
2 dirname = 'MTOOutput'
----> 3 xl_model = formulas.ExcelModel().loads(fpath).finish(circular=True)
4 xl_model.calculate()
5 xl_model.write(dirpath=dirname)
~/.local/lib/python3.8/site-packages/formulas/excel/__init__.py in loads(self, *file_names)
93 def loads(self, *file_names):
94 for filename in file_names:
---> 95 self.load(filename)
96 return self
97
~/.local/lib/python3.8/site-packages/formulas/excel/__init__.py in load(self, filename)
98 def load(self, filename):
99 book, context = self.add_book(filename)
--> 100 self.pushes(*book.worksheets, context=context)
101 return self
102
~/.local/lib/python3.8/site-packages/formulas/excel/__init__.py in pushes(self, context, *worksheets)
106 def pushes(self, *worksheets, context=None):
107 for ws in worksheets:
--> 108 self.push(ws, context=context)
109 return self
110
~/.local/lib/python3.8/site-packages/formulas/excel/__init__.py in push(self, worksheet, context)
119 for c in row:
120 if hasattr(c, 'value'):
--> 121 self.add_cell(
122 c, context, references=references,
123 formula_references=formula_references,
~/.local/lib/python3.8/site-packages/formulas/excel/__init__.py in add_cell(self, cell, context, references, formula_references, formula_ranges, external_links)
232 val = cell.data_type == 'f' and val[:2] == '==' and val[1:] or val
233 check_formula = cell.data_type != 's'
--> 234 cell = Cell(crd, val, context=ctx, check_formula=check_formula).compile(
235 references=references, context=ctx
236 )
~/.local/lib/python3.8/site-packages/formulas/cell.py in compile(self, references, context)
88 def compile(self, references=None, context=None):
89 if self.builder:
---> 90 func = self.builder.compile(
91 references=references, context=context, **{CELL: self.range}
92 )
~/.local/lib/python3.8/site-packages/formulas/builder.py in compile(self, references, context, **inputs)
127 else:
128 try:
--> 129 i[k] = Ranges().push(k, context=context)
130 except ValueError:
131 i[k] = None
~/.local/lib/python3.8/site-packages/formulas/ranges.py in push(self, ref, value, context)
167
168 def push(self, ref, value=sh.EMPTY, context=None):
--> 169 rng = self.get_range(self.format_range, ref, context)
170 return self.set_value(rng, value)
171
~/.local/lib/python3.8/site-packages/formulas/ranges.py in get_range(format_range, ref, context)
159 def get_range(format_range, ref, context=None):
160 ctx = (context or {}).copy()
--> 161 for k, v in _re_range.match(ref).groupdict().items():
162 if v is not None:
163 if k == 'ref':
AttributeError: 'NoneType' object has no attribute 'groupdict'
I initially had not used the circular=True argument inside finish. But after a bit of trouble shooting I realized that could be the problem. I say that could because I did not create the excel sheet and hence do not know much about what is in there.
I also tried installing the formulas[all] version again after a bit of troubleshooting before getting the same error. I tried including the use of range references in my test file to check if that was causing the issue. However the test file worked fine with range references. I was wondering if anyone who had faced an issue like this with formulas had found a solution or an alternative.
PS: It would not be possible for me to attach the excel file as it is work related.
Thanks and Regards,
Yadhu

AttributeError: dense_prediction_cell_json - Why can't the json file be loaded?

I'm trying to implement the DeepLab Model into a Tensorflow environment.
This is the github Repository: https://github.com/tensorflow/models/tree/master/research/deeplab
I'm using Python 3.6.8 and the Jupyter Notebook.
Now I'm facing the problem, that I can't run the train.py. I'm getting the AttributeError: dense_prediction_cell_json and I don't understand why.
I've tried to change the code to get the path right into the variable. Everytime the same error. The .json-file is in the right repository.
AttributeError Traceback (most recent call last)
<ipython-input-10-82da774ae9f4> in <module>
2 flags.mark_flag_as_required('train_logdir')
3 flags.mark_flag_as_required('dataset_dir')
----> 4 tf.app.run()
~\Anaconda\Anaconda3\envs\Tensorflow-GPU\lib\site-packages\tensorflow\python\platform\app.py in run(main, argv)
123 # Call the main function, passing through any arguments
124 # to the final program.
--> 125 _sys.exit(main(argv))
126
<ipython-input-9-5ba5cfdf622b> in main(unused_argv)
32 train_tensor, summary_op = _train_deeplab_model(
33 dataset.get_one_shot_iterator(), dataset.num_of_classes,
---> 34 dataset.ignore_label)
35
36 # Soft placement allows placing on CPU ops without GPU implementation.
<ipython-input-8-75f72f4530ec> in _train_deeplab_model(iterator, num_of_classes, ignore_label)
34 ignore_label=ignore_label,
35 scope=scope,
---> 36 reuse_variable=(i != 0))
37 tower_losses.append(loss)
38
<ipython-input-5-a0f1ad776056> in _tower_loss(iterator, num_of_classes, ignore_label, scope, reuse_variable)
14 with tf.variable_scope(
15 tf.get_variable_scope(), reuse=True if reuse_variable else None):
---> 16 _build_deeplab(iterator, {common.OUTPUT_TYPE: num_of_classes}, ignore_label)
17
18 losses = tf.losses.get_losses(scope=scope)
<ipython-input-4-54ae914e10d7> in _build_deeplab(iterator, outputs_to_num_classes, ignore_label)
19 crop_size=[int(sz) for sz in FLAGS.train_crop_size],
20 atrous_rates=FLAGS.atrous_rates,
---> 21 output_stride=FLAGS.output_stride)
22
23 outputs_to_scales_to_logits = model.multi_scale_logits(
~\Anaconda\DeepLab\models\research\deeplab\common.py in __new__(cls, outputs_to_num_classes, crop_size, atrous_rates, output_stride, preprocessed_images_dtype)
190
191 dense_prediction_cell_config = None
--> 192 if FLAGS.dense_prediction_cell_json:
193 with tf.gfile.Open(FLAGS.dense_prediction_cell_json, 'r') as f:
194 dense_prediction_cell_config = json.load(f)
~\Anaconda\Anaconda3\envs\Tensorflow-GPU\lib\site-packages\tensorflow\python\platform\flags.py in __getattr__(self, name)
83 if not wrapped.is_parsed():
84 wrapped(_sys.argv)
---> 85 return wrapped.__getattr__(name)
86
87 def __setattr__(self, name, value):
~\Anaconda\Anaconda3\envs\Tensorflow-GPU\lib\site-packages\absl\flags\_flagvalues.py in __getattr__(self, name)
471 fl = self._flags()
472 if name not in fl:
--> 473 raise AttributeError(name)
474 if name in self.__dict__['__hiddenflags']:
475 raise AttributeError(name)
AttributeError: dense_prediction_cell_json
In the common.py file the flag is defined as:
flags.DEFINE_string(
'dense_prediction_cell_json',
'./core/dense_prediction_cell_branch5_top1_cityscapes.json',
'A JSON file that specifies the dense prediction cell.')

SageMath notebook is not opening

I'm trying to open the Sage's notebook, but it isn't working.
I have no idea where this error came from, because the notebook was working this week. I guess it just popped up out of nowhere.
The message's error is:
sage: notebook()
---------------------------------------------------------------------------
EnvironmentError Traceback (most recent call last)
<ipython-input-4-3728cb3d7c7d> in <module>()
----> 1 notebook()
/home/jerome/opt/SageMath/src/sage/misc/lazy_import.pyx in sage.misc.lazy_import.LazyImport.__call__ (/home/jerome/opt/SageMath/src/build/cythonized/sage/misc/lazy_import.c:3634)()
384 True
385 """
--> 386 return self._get_object()(*args, **kwds)
387
388 def __repr__(self):
/home/jerome/opt/SageMath/src/sage/misc/lazy_import.pyx in sage.misc.lazy_import.LazyImport._get_object (/home/jerome/opt/SageMath/src/build/cythonized/sage/misc/lazy_import.c:2241)()
244 elif self._at_startup and not startup_guard:
245 print('Option ``at_startup=True`` for lazy import {0} not needed anymore'.format(self._name))
--> 246 self._object = getattr(__import__(self._module, {}, {}, [self._name]), self._name)
247 alias = self._as_name or self._name
248 if self._deprecation is not None:
/home/jerome/opt/SageMath/local/lib/python2.7/site-packages/sagenb/notebook/notebook_object.py in <module>()
15 import time, os, shutil, signal, tempfile
16
---> 17 import notebook as _notebook
18
19 import run_notebook
/home/jerome/opt/SageMath/local/lib/python2.7/site-packages/sagenb/notebook/notebook.py in <module>()
33
34 # Sage libraries
---> 35 from sagenb.misc.misc import (pad_zeros, cputime, tmp_dir, load, save,
36 ignore_nonexistent_files, unicode_str)
37
/home/jerome/opt/SageMath/local/lib/python2.7/site-packages/sagenb/misc/misc.py in <module>()
379
380 try:
--> 381 from sage.misc.cython import cython
382 except ImportError:
383 #stub
/home/jerome/opt/SageMath/local/lib/python2.7/site-packages/sage/misc/cython.py in <module>()
28
29 # CBLAS can be one of multiple implementations
---> 30 cblas_pc = pkgconfig.parse('cblas')
31 cblas_libs = list(cblas_pc['libraries'])
32 cblas_library_dirs = list(cblas_pc['library_dirs'])
/home/jerome/opt/SageMath/local/lib/python2.7/site-packages/pkgconfig-1.1.0-py2.7.egg/pkgconfig/pkgconfig.py in parse(packages)
185
186 for package in packages.split():
--> 187 for k, v in parse_package(package).items():
188 result[k].update(v)
189
/home/jerome/opt/SageMath/local/lib/python2.7/site-packages/pkgconfig-1.1.0-py2.7.egg/pkgconfig/pkgconfig.py in parse_package(package)
158
159 # Execute the query to pkg-config and clean the result.
--> 160 out = _query(package, '--cflags --libs')
161 out = out.replace('\\"', '')
162
/home/jerome/opt/SageMath/local/lib/python2.7/site-packages/pkgconfig-1.1.0-py2.7.egg/pkgconfig/pkgconfig.py in _wrapper(*args, **kwargs)
56 return func(*args, **kwargs)
57 except OSError:
---> 58 raise EnvironmentError("pkg-config is not installed")
59
60 return _wrapper
EnvironmentError: pkg-config is not installed
If you guys can help me, I'll be very thankful!

Why I am getting the following error opening a xlsx?

Hello I am trying to open a .xlsx file with python, my code is really simple it looks as follows:
import openpyxl
wb = openpyxl.load_workbook('prod334.xlsx')
However I am getting an error, I am not sure about the cause of this error since I am just opening the file, I would like to appreciate any suggestion to overcome this failure.
The error that I am getting is the following:
__init__() got an unexpected keyword argument 'vertAlign'
TypeError Traceback (most recent call last)
main.py in <module>()
2
3
----> 4 wb = openpyxl.load_workbook('prod334.xlsx')
/usr/local/lib/anaconda/lib/python2.7/site-packages/openpyxl/reader/excel.pyc in load_workbook(filename, use_iterators, keep_vba, guess_types, data_only)
163
164 try:
--> 165 _load_workbook(wb, archive, filename, use_iterators, keep_vba)
166 except KeyError:
167 e = exc_info()[1]
/usr/local/lib/anaconda/lib/python2.7/site-packages/openpyxl/reader/excel.pyc in _load_workbook(wb, archive, filename, use_iterators, keep_vba)
210 assert wb.loaded_theme == None, "even though the theme information is missing there is a theme object ?"
211
--> 212 style_properties = read_style_table(archive.read(ARC_STYLE))
213 style_table = style_properties.pop('table')
214 wb.shared_styles = style_properties.pop('list')
/usr/local/lib/anaconda/lib/python2.7/site-packages/openpyxl/reader/style.pyc in read_style_table(xml_source)
221 def read_style_table(xml_source):
222 p = SharedStylesParser(xml_source)
--> 223 p.parse()
224 return p.style_prop
/usr/local/lib/anaconda/lib/python2.7/site-packages/openpyxl/reader/style.pyc in parse(self)
37 self.parse_color_index()
38 self.style_prop['color_index'] = self.color_index
---> 39 self.font_list = list(self.parse_fonts())
40 self.fill_list = list(self.parse_fills())
41 self.border_list = list(self.parse_borders())
/usr/local/lib/anaconda/lib/python2.7/site-packages/openpyxl/reader/style.pyc in parse_fonts(self)
89 if fonts is not None:
90 for node in safe_iterator(fonts, '{%s}font' % SHEET_MAIN_NS):
---> 91 yield self.parse_font(node)
92
93 def parse_font(self, font_node):
/usr/local/lib/anaconda/lib/python2.7/site-packages/openpyxl/reader/style.pyc in parse_font(self, font_node)
105 if color is not None:
106 font['color'] = Color(**dict(color.items()))
--> 107 return Font(**font)
108
109 def parse_fills(self):
TypeError: __init__() got an unexpected keyword argument 'vertAlign'

Using Sacred Module with iPython

I am trying to set up sacred for Python and I am going through the tutorial. I was able to set up sacred using pip install sacred with no issues. I am having trouble running the basic code:
from sacred import Experiment
ex = Experiment("hello_world")
Running this code returns the a ValueError:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-25-66f549cfb192> in <module>()
1 from sacred import Experiment
2
----> 3 ex = Experiment("hello_world")
/Users/ryandevera/anaconda/lib/python2.7/site-packages/sacred/experiment.pyc in __init__(self, name, ingredients)
42 super(Experiment, self).__init__(path=name,
43 ingredients=ingredients,
---> 44 _caller_globals=caller_globals)
45 self.default_command = ""
46 self.command(print_config, unobserved=True)
/Users/ryandevera/anaconda/lib/python2.7/site-packages/sacred/ingredient.pyc in __init__(self, path, ingredients, _caller_globals)
48 self.doc = _caller_globals.get('__doc__', "")
49 self.sources, self.dependencies = \
---> 50 gather_sources_and_dependencies(_caller_globals)
51
52 # =========================== Decorators ==================================
/Users/ryandevera/anaconda/lib/python2.7/site-packages/sacred/dependencies.pyc in gather_sources_and_dependencies(globs)
204 def gather_sources_and_dependencies(globs):
205 dependencies = set()
--> 206 main = Source.create(globs.get('__file__'))
207 sources = {main}
208 experiment_path = os.path.dirname(main.filename)
/Users/ryandevera/anaconda/lib/python2.7/site-packages/sacred/dependencies.pyc in create(filename)
61 if not filename or not os.path.exists(filename):
62 raise ValueError('invalid filename or file not found "{}"'
---> 63 .format(filename))
64
65 mainfile = get_py_file_if_possible(os.path.abspath(filename))
ValueError: invalid filename or file not found "None"
I am not sure why this error is returning. The documentation does not say anything about setting up an Experiment file prior to running the code. Any help would be greatly appreciated!
The traceback given indicates that the constructor for Experiment searches its namespace to find the file in which its defined.
Thus, to make the example work, place the example code into a file and run that file directly.
If you are using ipython, then you could always try using the %%python command, which will effectively capture the code you give it into a file before running it (in a separate python process).
According to the docs, if you're in IPython/Jupyter, you can allow the Experiment to run in a non-reproducible interactive environment:
ex = Experiment('jupyter_ex', interactive=True)
https://sacred.readthedocs.io/en/latest/experiment.html#run-the-experiment
The docs say it nicely (TL;DR: sacred checks this for you and fails in order to warn you)
Warning
By default, Sacred experiments will fail if run in an interactive
environment like a REPL or a Jupyter Notebook. This is an intended
security measure since in these environments reproducibility cannot be
ensured. If needed, this safeguard can be deactivated by passing
interactive=True to the experiment like this:
ex = Experiment('jupyter_ex', interactive=True)
Setting interactive=True doesn't work if you run the notebook as a script through ipython.
$ ipython code.ipynb
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
Cell In[1], line 1
----> 1 ex = Experiment("image_classification", interactive=True)
2 ex.observers.append(NeptuneObserver(run=neptune_run))
File ~\miniconda3\envs\py38\lib\site-packages\sacred\experiment.py:119, in Experiment.__init__(self, name, ingredients, interactive, base_dir, additional_host_info, additional_cli_options, save_git_info)
117 elif name.endswith(".pyc"):
118 name = name[:-4]
--> 119 super().__init__(
120 path=name,
121 ingredients=ingredients,
122 interactive=interactive,
123 base_dir=base_dir,
124 _caller_globals=caller_globals,
125 save_git_info=save_git_info,
126 )
127 self.default_command = None
128 self.command(print_config, unobserved=True)
File ~\miniconda3\envs\py38\lib\site-packages\sacred\ingredient.py:75, in Ingredient.__init__(self, path, ingredients, interactive, _caller_globals, base_dir, save_git_info)
69 self.save_git_info = save_git_info
70 self.doc = _caller_globals.get("__doc__", "")
71 (
72 self.mainfile,
73 self.sources,
74 self.dependencies,
---> 75 ) = gather_sources_and_dependencies(
76 _caller_globals, save_git_info, self.base_dir
77 )
78 if self.mainfile is None and not interactive:
79 raise RuntimeError(
80 "Defining an experiment in interactive mode! "
81 "The sourcecode cannot be stored and the "
82 "experiment won't be reproducible. If you still"
83 " want to run it pass interactive=True"
84 )
File ~\miniconda3\envs\py38\lib\site-packages\sacred\dependencies.py:725, in gather_sources_and_dependencies(globs, save_git_info, base_dir)
723 def gather_sources_and_dependencies(globs, save_git_info, base_dir=None):
724 """Scan the given globals for modules and return them as dependencies."""
--> 725 experiment_path, main = get_main_file(globs, save_git_info)
727 base_dir = base_dir or experiment_path
729 gather_sources = source_discovery_strategies[SETTINGS["DISCOVER_SOURCES"]]
File ~\miniconda3\envs\py38\lib\site-packages\sacred\dependencies.py:596, in get_main_file(globs, save_git_info)
594 main = None
595 else:
--> 596 main = Source.create(globs.get("__file__"), save_git_info)
461 return Source(main_file, get_digest(main_file), repo, commit, is_dirty)
File ~\miniconda3\envs\py38\lib\site-packages\sacred\dependencies.py:382, in get_py_file_if_possible(pyc_name)
380 if pyc_name.endswith((".py", ".so", ".pyd")):
381 return pyc_name
--> 382 assert pyc_name.endswith(".pyc")
383 non_compiled_file = pyc_name[:-1]
384 if os.path.exists(non_compiled_file):
sacred==0.8.2

Categories