Unable to import cfgrib - netcdf

Whenever I try importing cfgrib it gives me runtime error that it could not load ecCodes library
import cfgrib
Here's the full error message
RuntimeError Traceback (most recent call last)
/tmp/ipykernel_6224/857012844.py in <module>
----> 1 import cfgrib
~/.local/lib/python3.8/site-packages/cfgrib/__init__.py in <module>
17
18 # cfgrib core API depends on the ECMWF ecCodes C-library only
---> 19 from .cfmessage import CfMessage
20 from .dataset import Dataset, DatasetBuildError, open_file, open_fileindex
21 from .messages import FileStream, Message
~/.local/lib/python3.8/site-packages/cfgrib/cfmessage.py in <module>
27 import numpy as np
28
---> 29 from . import abc, messages
30
31 LOG = logging.getLogger(__name__)
~/.local/lib/python3.8/site-packages/cfgrib/messages.py in <module>
26
27 import attr
---> 28 import eccodes # type: ignore
29 import numpy as np
30
~/.local/lib/python3.8/site-packages/eccodes/__init__.py in <module>
13 import sys
14
---> 15 from .eccodes import *
16 from .eccodes import __version__
17 from .eccodes import bindings_version
~/.local/lib/python3.8/site-packages/eccodes/eccodes.py in <module>
10 #
11 #
---> 12 from gribapi import __version__
13 from gribapi import bindings_version
14
~/.local/lib/python3.8/site-packages/gribapi/__init__.py in <module>
11 #
12
---> 13 from .gribapi import * # noqa
14 from .gribapi import __version__
15 from .gribapi import bindings_version
~/.local/lib/python3.8/site-packages/gribapi/gribapi.py in <module>
2226
2227
-> 2228 __version__ = grib_get_api_version()
2229
2230
~/.local/lib/python3.8/site-packages/gribapi/gribapi.py in grib_get_api_version()
2216
2217 if not lib:
-> 2218 raise RuntimeError("Could not load the ecCodes library!")
2219
2220 v = lib.grib_get_api_version()
RuntimeError: Could not load the ecCodes library!
I have installed cfgrib and ecCodes through pip
cfgrib 0.9.9.1
eccodes 1.4.0
eccodes-python 0.9.9

As stated on pypi (https://pypi.org/project/eccodes/) the eccodes python package relies on the eccodes system library. Based on the error message, you do not have it installed.
It is probably easiest to install it using conda:
conda install -c conda-forge eccodes

Related

Not able to use NERModel due to import issue from SimpleTransformers

I'm trying to use SimpleTransformers module for this competition.
After successfully installing the package SimpleTransformers in kernel , i'm trying to import NERModel and NERArgs packages from simpletransformers.ner. But i get error message as below.
**
!pip install SimpleTransformers
#(The above statement works fine.)
from simpletransformers.ner import NERModel,NERArgs
#(While executing the above statement , getting below error)
ImportError Traceback (most recent call last)
in
1 get_ipython().system('pip install --upgrade fsspec')
----> 2 from simpletransformers.ner import NERModel,NERArgs
/opt/conda/lib/python3.7/site-packages/simpletransformers/ner/init.py in
1 from simpletransformers.config.model_args import NERArgs
----> 2 from simpletransformers.ner.ner_model import NERModel
/opt/conda/lib/python3.7/site-packages/simpletransformers/ner/ner_model.py in
30 )
31 from transformers.optimization import AdamW, Adafactor
---> 32 from transformers import (
33 AlbertConfig,
34 AlbertForTokenClassification,
/opt/conda/lib/python3.7/site-packages/transformers/init.py in getattr(self, name)
2485 if name == "version":
2486 return version
-> 2487 return super().getattr(name)
2488
2489 sys.modules[name] = _LazyModule(name, _import_structure)
/opt/conda/lib/python3.7/site-packages/transformers/file_utils.py in getattr(self, name)
1698 elif name in self._class_to_module.keys():
1699 module = self._get_module(self._class_to_module[name])
-> 1700 value = getattr(module, name)
1701 else:
1702 raise AttributeError(f"module {self.name} has no attribute {name}")
/opt/conda/lib/python3.7/site-packages/transformers/file_utils.py in getattr(self, name)
1697 value = self._get_module(name)
1698 elif name in self._class_to_module.keys():
-> 1699 module = self._get_module(self._class_to_module[name])
1700 value = getattr(module, name)
1701 else:
/opt/conda/lib/python3.7/site-packages/transformers/models/auto/init.py in _get_module(self, module_name)
196
197 def _get_module(self, module_name: str):
--> 198 return importlib.import_module("." + module_name, self.name)
199
200 sys.modules[name] = _LazyModule(name, _import_structure)
/opt/conda/lib/python3.7/importlib/init.py in import_module(name, package)
125 break
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
128
129
/opt/conda/lib/python3.7/site-packages/transformers/models/auto/modeling_auto.py in
197 from ..pegasus.modeling_pegasus import PegasusForCausalLM, PegasusForConditionalGeneration, PegasusModel
198 from ..prophetnet.modeling_prophetnet import ProphetNetForCausalLM, ProphetNetForConditionalGeneration, ProphetNetModel
--> 199 from ..rag.modeling_rag import ( # noqa: F401 - need to import all RagModels to be in globals() function
200 RagModel,
201 RagSequenceForGeneration,
/opt/conda/lib/python3.7/site-packages/transformers/models/rag/modeling_rag.py in
27 from …utils import logging
28 from .configuration_rag import RagConfig
---> 29 from .retrieval_rag import RagRetriever
30
31
/opt/conda/lib/python3.7/site-packages/transformers/models/rag/retrieval_rag.py in
37
38 if is_datasets_available():
---> 39 from datasets import Dataset, load_dataset, load_from_disk
40
41 if is_faiss_available():
/opt/conda/lib/python3.7/site-packages/datasets/init.py in
31 )
32
---> 33 from .arrow_dataset import Dataset, concatenate_datasets
34 from .arrow_reader import ArrowReader, ReadInstruction
35 from .arrow_writer import ArrowWriter
/opt/conda/lib/python3.7/site-packages/datasets/arrow_dataset.py in
44 from .arrow_writer import ArrowWriter, OptimizedTypedSequence
45 from .features import ClassLabel, Features, Value, cast_to_python_objects
---> 46 from .filesystems import extract_path_from_uri, is_remote_filesystem
47 from .fingerprint import (
48 fingerprint_transform,
/opt/conda/lib/python3.7/site-packages/datasets/filesystems/init.py in
7
8 if _has_s3fs:
----> 9 from .s3filesystem import S3FileSystem # noqa: F401
10
11
/opt/conda/lib/python3.7/site-packages/datasets/filesystems/s3filesystem.py in
----> 1 import s3fs
2
3
4 class S3FileSystem(s3fs.S3FileSystem):
5 """
/opt/conda/lib/python3.7/site-packages/s3fs/init.py in
----> 1 from .core import S3FileSystem, S3File
2 from .mapping import S3Map
3
4 from ._version import get_versions
5
/opt/conda/lib/python3.7/site-packages/s3fs/core.py in
9
10 from fsspec.spec import AbstractBufferedFile
---> 11 from fsspec.utils import infer_storage_options, tokenize, setup_logging
12 from fsspec.asyn import AsyncFileSystem, sync, sync_wrapper
13
ImportError: cannot import name 'setup_logging' from 'fsspec.utils' (/opt/conda/lib/python3.7/site-packages/fsspec/utils.py)
This has become show stopper for me in kaggle.The same code works in Colab.Please advice.**
Thanks,
Shyam.
fsspec==0.9.0 has the function fsspec.utils.setup_logging but earlier versions do not
Try pip install fsspec==0.9.0
see: https://githubmemory.com/repo/dask/s3fs/activity?page=3

Import Error while importing TensorLy in Jupyter Notebook

I'm trying to import TensorLy in Jupyter notebook as import tensorly as tl but I'm getting Import Error. I have TensorLy installed on my local machine.
Complete traceback:
ImportError Traceback (most recent call last)
<ipython-input-5-7285d7cdd476> in <module>
----> 1 import tensorly as tl
c:\users\jaydeep borkar\desktop\tensorly\tensorly\__init__.py in <module>
2 import sys
3
----> 4 from .base import unfold, fold
5 from .base import tensor_to_vec, vec_to_tensor
6 from .base import partial_unfold, partial_fold
c:\users\jaydeep borkar\desktop\tensorly\tensorly\base.py in <module>
----> 1 from . import backend as T
2
3 def tensor_to_vec(tensor):
4 """Vectorises a tensor
5
c:\users\jaydeep borkar\desktop\tensorly\tensorly\backend\__init__.py in <module>
1 import warnings
----> 2 from .core import Backend
3 import importlib
4 import os
5 import sys
c:\users\jaydeep borkar\desktop\tensorly\tensorly\backend\core.py in <module>
9 import numpy as np
10 import scipy.linalg
---> 11 import scipy.sparse.linalg
12
13
C:\Anaconda3\lib\site-packages\scipy\sparse\linalg\__init__.py in <module>
115 from .dsolve import *
116 from .interface import *
--> 117 from .eigen import *
118 from .matfuncs import *
119 from ._onenormest import *
C:\Anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\__init__.py in <module>
9 from __future__ import division, print_function, absolute_import
10
---> 11 from .arpack import *
12 from .lobpcg import *
13
C:\Anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\arpack\__init__.py in <module>
20 from __future__ import division, print_function, absolute_import
21
---> 22 from .arpack import *
C:\Anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\arpack\arpack.py in <module>
43 __all__ = ['eigs', 'eigsh', 'svds', 'ArpackError', 'ArpackNoConvergence']
44
---> 45 from . import _arpack
46 import numpy as np
47 import warnings
ImportError: DLL load failed: The specified procedure could not be found.
What can be the possible solution?
Are you using a new conda environment? If so try this out.

rpy2 Installed But Won't Run Packages

I've been able to install rpy2 via conda:
conda install -c r rpy2
However, the only function that works is:
import rpy2
I confirm I'm running:
rpy v 2.9.0
3.5.2 |Anaconda custom (64-bit)| (default, Jul 5 2016, 11:41:13) [MSC v.1900 64 bit (AMD64)]
Window 10
Error example:
from rpy2 import robjects
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-46-1f019d00d232> in <module>()
----> 1 from rpy2 import robjects
C:\Users\cfeld\AppData\Local\Continuum\Anaconda3\lib\site-packages\rpy2-2.9.0-py3.5-win-amd64.egg\rpy2\robjects\__init__.py in <module>()
14 import itertools
15 from datetime import datetime
---> 16 import rpy2.rinterface as rinterface
17 import rpy2.rlike.container as rlc
18
C:\Users\cfeld\AppData\Local\Continuum\Anaconda3\lib\site-packages\rpy2-2.9.0-py3.5-win-amd64.egg\rpy2\rinterface\__init__.py in <module>()
43
44 if sys.platform == 'win32':
---> 45 _load_r_dll(R_HOME)
46
47 # cleanup the namespace
C:\Users\cfeld\AppData\Local\Continuum\Anaconda3\lib\site-packages\rpy2-2.9.0-py3.5-win-amd64.egg\rpy2\rinterface\__init__.py in _load_r_dll(r_home)
27 if r_bin not in os.environ.get('PATH'):
28 os.environ['PATH'] = ';'.join((os.environ.get('PATH'), r_bin, r_mod))
---> 29 ctypes.CDLL(r_dll)
30
31 R_HOME = get_r_home()
C:\Users\cfeld\AppData\Local\Continuum\Anaconda3\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
345
346 if handle is None:
--> 347 self._handle = _dlopen(self._name, mode)
348 else:
349 self._handle = handle
OSError: [WinError 126] The specified module could not be found
Any suggestions?

%R magic no longer works in IPython or Jupyter following update to Canopy Ver 1.7.4.3348

Previously %R and %%R magics were working in IPython and Jupyter python notebooks.
The R terminal version is:
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)
After upgrading to Version 1.7.4.3348 in Enthought Canopy, the notebooks and IPython no longer work. I have tried reinstalling following Installing RKernel and http://irkernel.github.io/installation/, which worked before. I run the command to load the R-extension as per
%load_ext rpy2.ipython
I get the error message as follows:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-691c6d73b073> in <module>()
----> 1 get_ipython().magic(u'load_ext rpy2.ipython')
/Users/Llewelyn_home/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
2161 magic_name, _, magic_arg_s = arg_s.partition(' ')
2162 magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2163 return self.run_line_magic(magic_name, magic_arg_s)
2164
2165 #-------------------------------------------------------------------------
/Users/Llewelyn_home/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)
2082 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
2083 with self.builtin_trap:
-> 2084 result = fn(*args,**kwargs)
2085 return result
2086
<decorator-gen-64> in load_ext(self, module_str)
/Users/Llewelyn_home/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)
191 # but it's overkill for just that one bit of state.
192 def magic_deco(arg):
--> 193 call = lambda f, *a, **k: f(*a, **k)
194
195 if callable(arg):
/Users/Llewelyn_home/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/magics/extension.pyc in load_ext(self, module_str)
64 if not module_str:
65 raise UsageError('Missing module name.')
---> 66 res = self.shell.extension_manager.load_extension(module_str)
67
68 if res == 'already loaded':
/Users/Llewelyn_home/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/extensions.pyc in load_extension(self, module_str)
82 if module_str not in sys.modules:
83 with prepended_to_syspath(self.ipython_extension_dir):
---> 84 __import__(module_str)
85 mod = sys.modules[module_str]
86 if self._call_load_ipython_extension(mod):
/Users/Llewelyn_home/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/rpy2/ipython/__init__.py in <module>()
----> 1 from .rmagic import load_ipython_extension
/Users/Llewelyn_home/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/rpy2/ipython/rmagic.py in <module>()
57 template_converter = ro.conversion.converter
58 try:
---> 59 from rpy2.robjects import pandas2ri as baseconversion
60 template_converter = template_converter + baseconversion.converter
61 except ImportError:
/Users/Llewelyn_home/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/rpy2/robjects/pandas2ri.py in <module>()
7 INTSXP)
8
----> 9 from pandas.core.frame import DataFrame as PandasDataFrame
10 from pandas.core.series import Series as PandasSeries
11 from pandas.core.index import Index as PandasIndex
/Users/Llewelyn_home/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/__init__.py in <module>()
20
21 # numpy compat
---> 22 from pandas.compat.numpy_compat import *
23
24 try:
/Users/Llewelyn_home/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/compat/numpy_compat.py in <module>()
13
14 # numpy versioning
---> 15 _np_version = np.version.short_version
16 _np_version_under1p8 = LooseVersion(_np_version) < '1.8'
17 _np_version_under1p9 = LooseVersion(_np_version) < '1.9'
AttributeError: 'module' object has no attribute 'version'
Could it be related to Canopy version of numpy being listed as 1.10.4-1 and the np.version result being 1.11.1 (based on error message)? Any suggestions gratefully received. PS. R works in the console still, plus in terminal and in Jupyter with an R kernel...
The support crew at Enthought examined the version of numpy, then pandas. Reinstalling both did not solve the problem. The unexplained resolution occurred from the pip install theano --upgrade command on the Canopy Terminal. Logging this error as an unexplained issue with %R but with the strong indication that it is about dependency version.

Issues running rmagic in IPython - Yosemite

I'm currently having issues trying to load rmagic into IPython since I upgraded to OSX Yosemite.
I'm using the following command:
%load_ext rmagic
Below is the error I'm getting, and I'm not sure if it's because I upgraded to Yosemite or because I'm trying to load R incorrectly. I've pasted all the Traceback in case that's useful, but the error ends in
ImportError: cannot import name conversion
My R version is 3.1.1
My Python version is 2.7.6
My IPython version is 2.3.0
Not sure what version rpy2 is, but I only downloaded it a few days ago so I assume it's the latest.
ImportError Traceback (most recent call last)
<ipython-input-7-691c6d73b073> in <module>()
----> 1 get_ipython().magic(u'load_ext rpy2.ipython')
/Library/Python/2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
2203 magic_name, _, magic_arg_s = arg_s.partition(' ')
2204 magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2205 return self.run_line_magic(magic_name, magic_arg_s)
2206
2207 #-------------------------------------------------------------------------
/Library/Python/2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)
2124 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
2125 with self.builtin_trap:
-> 2126 result = fn(*args,**kwargs)
2127 return result
2128
/Library/Python/2.7/site-packages/IPython/core/magics/extension.pyc in load_ext(self, module_str)
/Library/Python/2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)
191 # but it's overkill for just that one bit of state.
192 def magic_deco(arg):
--> 193 call = lambda f, *a, **k: f(*a, **k)
194
195 if callable(arg):
/Library/Python/2.7/site-packages/IPython/core/magics/extension.pyc in load_ext(self, module_str)
61 if not module_str:
62 raise UsageError('Missing module name.')
---> 63 res = self.shell.extension_manager.load_extension(module_str)
64
65 if res == 'already loaded':
/Library/Python/2.7/site-packages/IPython/core/extensions.pyc in load_extension(self, module_str)
96 if module_str not in sys.modules:
97 with prepended_to_syspath(self.ipython_extension_dir):
---> 98 __import__(module_str)
99 mod = sys.modules[module_str]
100 if self._call_load_ipython_extension(mod):
/Library/Python/2.7/site-packages/rpy2/ipython/__init__.py in <module>()
----> 1 from .rmagic import load_ipython_extension
/Library/Python/2.7/site-packages/rpy2/ipython/rmagic.py in <module>()
51
52 import rpy2.rinterface as ri
---> 53 import rpy2.robjects as ro
54 import rpy2.robjects.packages as rpacks
55
/Library/Python/2.7/site-packages/rpy2/robjects/__init__.py in <module>()
16 import rpy2.rlike.container as rlc
17
---> 18 from rpy2.robjects.robject import RObjectMixin, RObject
19 from rpy2.robjects.vectors import *
20 from rpy2.robjects.functions import Function, SignatureTranslatedFunction
/Library/Python/2.7/site-packages/rpy2/robjects/robject.py in <module>()
5 rpy2.rinterface.initr()
6
----> 7 from . import conversion
8
9 class RObjectMixin(object):
ImportError: cannot import name conversion
Minrk had it right - uninstalling and reinstalling rpy2 fixed my problem. Not sure why I didn't think of that before! Thanks.

Resources