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

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.

Related

Why do I get No module named 'sympy.series.approximants' error when importing Sympy with anaconda?

Sympy is downloaded with anaconda. In a Jupyter notebook, I have 'from sympy import divisors' and I get this:
ModuleNotFoundError Traceback (most recent call last)
Cell In[12], line 1
----> 1 from sympy import divisors
File ~/Desktop/anaconda3/lib/python3.9/site-packages/sympy/__init__.py:107
70 from .assumptions import (AppliedPredicate, Predicate, AssumptionsContext,
71 assuming, Q, ask, register_handler, remove_handler, refine)
73 from .polys import (Poly, PurePoly, poly_from_expr, parallel_poly_from_expr,
74 degree, total_degree, degree_list, LC, LM, LT, pdiv, prem, pquo,
75 pexquo, div, rem, quo, exquo, half_gcdex, gcdex, invert,
(...)
104 laguerre_poly, apart, apart_list, assemble_partfrac_list, Options,
105 ring, xring, vring, sring, field, xfield, vfield, sfield)
--> 107 from .series import (Order, O, limit, Limit, gruntz, series, approximants,
108 residue, EmptySequence, SeqPer, SeqFormula, sequence, SeqAdd, SeqMul,
109 fourier_series, fps, difference_delta, limit_seq)
111 from .functions import (factorial, factorial2, rf, ff, binomial,
112 RisingFactorial, FallingFactorial, subfactorial, carmichael,
113 fibonacci, lucas, motzkin, tribonacci, harmonic, bernoulli, bell, euler,
(...)
132 Znm, elliptic_k, elliptic_f, elliptic_e, elliptic_pi, beta, mathieus,
133 mathieuc, mathieusprime, mathieucprime, riemann_xi, betainc, betainc_regularized)
135 from .ntheory import (nextprime, prevprime, prime, primepi, primerange,
136 randprime, Sieve, sieve, primorial, cycle_length, composite,
137 compositepi, isprime, divisors, proper_divisors, factorint,
(...)
148 continued_fraction_iterator, continued_fraction_reduce,
149 continued_fraction_convergents, continued_fraction, egyptian_fraction)
File ~/Desktop/anaconda3/lib/python3.9/site-packages/sympy/series/__init__.py:7
5 from .gruntz import gruntz
6 from .series import series
----> 7 from .approximants import approximants
8 from .residues import residue
9 from .sequences import SeqPer, SeqFormula, sequence, SeqAdd, SeqMul
ModuleNotFoundError: No module named 'sympy.series.approximants'
Any ideas on what I am doing wrong? Thank you.
Tried using the terminal to update, but I am garbage with anything beyond the basics.

Getting error while installing lme4 package in R in MacOSX Monterey

I am getting the following error when trying to install the lme4 package in R.
install.packages("lme4")
Installing package into ‘/usr/local/lib/R/4.2/site-library’
(as ‘lib’ is unspecified)
also installing the dependency ‘minqa’
trying URL 'https://cloud.r-project.org/src/contrib/minqa_1.2.4.tar.gz'
Content type 'application/x-gzip' length 53548 bytes (52 KB)
==================================================
downloaded 52 KB
trying URL 'https://cloud.r-project.org/src/contrib/lme4_1.1-29.tar.gz'
Content type 'application/x-gzip' length 3306026 bytes (3.2 MB)
==================================================
downloaded 3.2 MB
* installing *source* package ‘minqa’ ...
** package ‘minqa’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
/usr/local/opt/gcc/bin/gfortran -fno-optimize-sibling-calls -fPIC -g -O2 -c altmov.f -o altmov.o
altmov.f:42:72:
42 | 10 HCOL(K)=ZERO
| 1
Warning: Fortran 2018 deleted feature: DO termination statement which is not END DO or CONTINUE with label 10 at (1)
altmov.f:45:72:
45 | DO 20 K=1,NPT
| 1
Warning: Fortran 2018 deleted feature: Shared DO termination label 20 at (1)
altmov.f:46:72:
46 | 20 HCOL(K)=HCOL(K)+TEMP*ZMAT(K,J)
| 1
Warning: Fortran 2018 deleted feature: DO termination statement which is not END DO or CONTINUE with label 20 at (1)
altmov.f:53:72:
53 | 30 GLAG(I)=BMAT(KNEW,I)
| 1
Warning: Fortran 2018 deleted feature: DO termination statement which is not END DO or CONTINUE with label 30 at (1)
altmov.f:57:72:
57 | 40 TEMP=TEMP+XPT(K,J)*XOPT(J)
| 1
Warning: Fortran 2018 deleted feature: DO termination statement which is not END DO or CONTINUE with label 40 at (1)
altmov.f:59:72:
59 | DO 50 I=1,N
| 1
Warning: Fortran 2018 deleted feature: Shared DO termination label 50 at (1)
altmov.f:60:72:
60 | 50 GLAG(I)=GLAG(I)+TEMP*XPT(K,I)
| 1
Warning: Fortran 2018 deleted feature: DO termination statement which is not END DO or CONTINUE with label 50 at (1)
altmov.f:76:72:
76 | 60 DISTSQ=DISTSQ+TEMP*TEMP
| 1
Warning: Fortran 2018 deleted feature: DO termination statement which is not END DO or CONTINUE with label 60 at (1)
altmov.f:172:72:
172 | 90 XNEW(I)=DMAX1(SL(I),DMIN1(SU(I),TEMP))
| 1
Warning: Fortran 2018 deleted feature: DO termination statement which is not END DO or CONTINUE with label 90 at (1)
altmov.f:237:72:
237 | 140 GW=GW+GLAG(I)*W(I)
| 1
Warning: Fortran 2018 deleted feature: DO termination statement which is not END DO or CONTINUE with label 140 at (1)
altmov.f:248:72:
248 | 150 TEMP=TEMP+XPT(K,J)*W(J)
| 1
Warning: Fortran 2018 deleted feature: DO termination statement which is not END DO or CONTINUE with label 150 at (1)
altmov.f:249:72:
249 | 160 CURV=CURV+HCOL(K)*TEMP*TEMP
| 1
Warning: Fortran 2018 deleted feature: DO termination statement which is not END DO or CONTINUE with label 160 at (1)
altmov.f:255:72:
255 | 170 XALT(I)=DMAX1(SL(I),DMIN1(SU(I),TEMP))
| 1
Warning: Fortran 2018 deleted feature: DO termination statement which is not END DO or CONTINUE with label 170 at (1)
altmov.f:268:72:
268 | 180 W(N+I)=XALT(I)
| 1
Warning: Fortran 2018 deleted feature: DO termination statement which is not END DO or CONTINUE with label 180 at (1)
altmov.f:275:72:
275 | 190 XALT(I)=W(N+I)
| 1
Warning: Fortran 2018 deleted feature: DO termination statement which is not END DO or CONTINUE with label 190 at (1)
clang (LLVM option parsing): Unknown command line argument '-x86-pad-for-align=false'. Try: 'clang (LLVM option parsing) --help'
clang (LLVM option parsing): Did you mean '--x86-slh-loads=false'?
make: *** [altmov.o] Error 1
ERROR: compilation failed for package ‘minqa’
* removing ‘/usr/local/lib/R/4.2/site-library/minqa’
ERROR: dependency ‘minqa’ is not available for package ‘lme4’
* removing ‘/usr/local/lib/R/4.2/site-library/lme4’
The downloaded source packages are in
‘/private/var/folders/02/6dwz1gvd1qz4gml8v_wv6n980000gp/T/RtmpVREiYV/downloaded_packages’
Warning messages:
1: In install.packages("lme4") :
installation of package ‘minqa’ had non-zero exit status
2: In install.packages("lme4") :
installation of package ‘lme4’ had non-zero exit status
I recently upgraded my OS to MacOSX Monterey (12.3.1) in a MacBook 2020 (intel chip).
I have tried reinstalling gcc and gccfortran using brew with no effect.
Can anyone help me with the issue?
Removing xcode command line tools and reinstalling it solved the issue.
$ xcode-select --print-path
/Library/Developer/CommandLineTools
$ sudo rm -r -f /Library/Developer/CommandLineTools
$ xcode-select --install

Unable to import cfgrib

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

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?

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