pybrms
pybrms copied to clipboard
Errors with pybrms
commands not recognized
epilepsy = pybrms.get_brms_data("epilepsy")
AttributeError Traceback (most recent call last)
AttributeError: module 'pybrms' has no attribute 'get_brms_data'
Thanks for reporting this! I'm planning to re-arrange the code to a proper package in the next following days, and I'll fix this along the way. I'll post here when its done.
I very much appreciate this. Current updates with stan on R have created some havoc with windows 10 users as stan is failing at the compilation stage. Efforts are being employed to fix it. I am a huge brms user and am fluent in both python and R but better at R since I use it more. BRMS has made Bayesian statistics more amenable for users and your package provides options for the user in their platform choice.
Fantastic!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Robert D. Johnson, Ph.D [cid:[email protected]] Procter & Gamble Mason Business Center 8700 Mason Montgomery Road [email protected]mailto:[email protected] (513) 634-9827
COVID19: I wish it need not have happened in my time and So do all who live to see such times. All we have to decide is what to do with the time that is given us
From: Adam Haber [email protected] Sent: Tuesday, July 21, 2020 7:31 AM To: adamhaber/pybrms [email protected] Cc: Johnson, Robert [email protected]; Author [email protected] Subject: Re: [adamhaber/pybrms] Errors with pybrms (#3)
Thanks for reporting this! I'm planning to re-arrange the code to a proper package in the next following days, and I'll fix this along the way. I'll post here when its done.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/adamhaber/pybrms/issues/3#issuecomment-661800613, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AD6MJ6BUGRFNDVFK4324F2DR4V36BANCNFSM4PCVOEAA.
Hi, I'm trying to better understand the problem so I can try and fix this. How did you install the library?
I ran into same error that started this thread:
Operating System: Ubuntu 20.04 using KDE Plasma Python Distribution: Anaconda 64-bit
I created a new environment "bayesian" and installed pymc3, pystan, bambi among others relevant for building hierarchical Bayesian models. I could run bambi and pymc3 successfully. Then I used "pip install pybrms" to install pybrms togo along wth rpy2-3.3.5 and other dependencies
Then I typed the following commands:
import pybrms # no error when I run this statement
epilepsy = pybrms.get_brms_data("epilepsy") # I got the same error as @pkpddude
Hope you can help resolve - I love brms and love the idea of using brms in Python
Sree
What happens if you do
from pybrms import pybrms
instead of
import pybrms
?
Thanks for the quick reply. I get these long set of errors with the new command: (I have posted the entire output)
WARNING:rpy2.rinterface_lib.callbacks:R[write to console]: Warning: WARNING:rpy2.rinterface_lib.callbacks:R[write to console]: failed to download mirrors file (long vectors not supported yet: libcurl.c:952); using local file '/home/sreezach/anaconda3/envs/bayesian/lib/R/doc/CRAN_mirrors.csv'
WARNING:rpy2.rinterface_lib.callbacks:R[write to console]: Error in unlink(f) : 3 arguments passed to .Internal(unlink) which requires 4
PackageNotInstalledError Traceback (most recent call last)
~/anaconda3/envs/bayesian/lib/python3.8/site-packages/pybrms/pybrms.py in
~/anaconda3/envs/bayesian/lib/python3.8/site-packages/rpy2/robjects/packages.py in importr(name, lib_loc, robject_translations, signature_translation, suppress_messages, on_conflict, symbol_r2python, symbol_resolve, data) 469 if not isinstalled(name, lib_loc=lib_loc): --> 470 raise PackageNotInstalledError( 471 'The R package "%s" is not installed.' % name
PackageNotInstalledError: The R package "brms" is not installed.
During handling of the above exception, another exception occurred:
RRuntimeError Traceback (most recent call last)
~/anaconda3/envs/bayesian/lib/python3.8/site-packages/pybrms/pybrms.py in
~/anaconda3/envs/bayesian/lib/python3.8/site-packages/rpy2/robjects/functions.py in call(self, *args, **kwargs) 195 v = kwargs.pop(k) 196 kwargs[r_k] = v --> 197 return (super(SignatureTranslatedFunction, self) 198 .call(*args, **kwargs)) 199
~/anaconda3/envs/bayesian/lib/python3.8/site-packages/rpy2/robjects/functions.py in call(self, *args, **kwargs) 123 else: 124 new_kwargs[k] = conversion.py2rpy(v) --> 125 res = super(Function, self).call(*new_args, **new_kwargs) 126 res = conversion.rpy2py(res) 127 return res
~/anaconda3/envs/bayesian/lib/python3.8/site-packages/rpy2/rinterface_lib/conversion.py in _(*args, **kwargs) 42 def _cdata_res_to_rinterface(function): 43 def _(*args, **kwargs): ---> 44 cdata = function(*args, **kwargs) 45 # TODO: test cdata is of the expected CType 46 return _cdata_to_rinterface(cdata)
~/anaconda3/envs/bayesian/lib/python3.8/site-packages/rpy2/rinterface.py in call(self, *args, **kwargs) 622 error_occured)) 623 if error_occured[0]: --> 624 raise embedded.RRuntimeError(_rinterface._geterrmessage()) 625 return res 626
RRuntimeError: Error in unlink(f) : 3 arguments passed to .Internal(unlink) which requires 4
Just a thought:
I have R 4.0.2 installed outside of Anaconda and I noticed that the rpy2 is using a r-base which is 3.6.1 - Is there any potential conflict here? My understanding says "no",but one could never be sure
Can you try running
import rpy2.robjects.packages as rpackages
from rpy2.robjects import StrVector
utils = rpackages.importr("utils")
utils.install_packages(StrVector(('brms',)))
brms = rpackages.importr("brms")
in the same conda environment?
If this succeeds, try
from pybrms import pybrms
epilepsy = pybrms.get_brms_data("epilepsy")
Get the same error as before:
--- Please select a CRAN mirror for use in this session --- WARNING:rpy2.rinterface_lib.callbacks:R[write to console]: Warning: WARNING:rpy2.rinterface_lib.callbacks:R[write to console]: failed to download mirrors file (long vectors not supported yet: libcurl.c:952); using local file '/home/sreezach/anaconda3/envs/bayesian/lib/R/doc/CRAN_mirrors.csv'
WARNING:rpy2.rinterface_lib.callbacks:R[write to console]: Error in unlink(f) : 3 arguments passed to .Internal(unlink) which requires 4
RRuntimeError Traceback (most recent call last)
~/anaconda3/envs/bayesian/lib/python3.8/site-packages/rpy2/robjects/functions.py in call(self, *args, **kwargs) 195 v = kwargs.pop(k) 196 kwargs[r_k] = v --> 197 return (super(SignatureTranslatedFunction, self) 198 .call(*args, **kwargs)) 199
~/anaconda3/envs/bayesian/lib/python3.8/site-packages/rpy2/robjects/functions.py in call(self, *args, **kwargs) 123 else: 124 new_kwargs[k] = conversion.py2rpy(v) --> 125 res = super(Function, self).call(*new_args, **new_kwargs) 126 res = conversion.rpy2py(res) 127 return res
~/anaconda3/envs/bayesian/lib/python3.8/site-packages/rpy2/rinterface_lib/conversion.py in _(*args, **kwargs) 42 def _cdata_res_to_rinterface(function): 43 def _(*args, **kwargs): ---> 44 cdata = function(*args, **kwargs) 45 # TODO: test cdata is of the expected CType 46 return _cdata_to_rinterface(cdata)
~/anaconda3/envs/bayesian/lib/python3.8/site-packages/rpy2/rinterface.py in call(self, *args, **kwargs) 622 error_occured)) 623 if error_occured[0]: --> 624 raise embedded.RRuntimeError(_rinterface._geterrmessage()) 625 return res 626
RRuntimeError: Error in unlink(f) : 3 arguments passed to .Internal(unlink) which requires 4
According to the last note here, removing utils.chooseCRANmirror(ind=1)
(which caused the error in the original post) should have sent you to an interactive session in which you could choose the mirror from which you download the package.
If I understand it correctly, you got --- Please select a CRAN mirror for use in this session ---
but then it crashed before you actually got to choose?
Anyway, this seems RPy2-related; I opened an issue on their repo, hope they can help.
@sreedta8 - following the answer on https://github.com/rpy2/rpy2/issues/735, can you try to:
-
pip uninstall rpy2
-
conda install -c r r-base
-
conda install -c r rpy2
(orpip install rpy2
if reinstalling with conda doesn't help)?
Thank you so much for the diligent and continued follow-up @adamhaber . I will try that and let you know asap.
Sree
Hi I still the same error after I recreatedand built a new environment from scratch. Do you know what the exact dependenciesfor rpy2 are? I tried and failed to locate. I'm wondering if it is a Python version issue!
Please select a CRAN mirror for use in this session --- R[write to console]: Warning: R[write to console]: failed to download mirrors file (long vectors not supported yet: libcurl.c:952); using local file '/home/sreezach/anaconda3/envs/bayesian/lib/R/doc/CRAN_mirrors.csv'
R[write to console]: Error in unlink(f) : 3 arguments passed to .Internal(unlink) which requires 4
RRuntimeError Traceback (most recent call last)
~/anaconda3/envs/bayesian/lib/python3.7/site-packages/rpy2/robjects/functions.py in call(self, *args, **kwargs) 196 kwargs[r_k] = v 197 return (super(SignatureTranslatedFunction, self) --> 198 .call(*args, **kwargs)) 199 200
~/anaconda3/envs/bayesian/lib/python3.7/site-packages/rpy2/robjects/functions.py in call(self, *args, **kwargs) 123 else: 124 new_kwargs[k] = conversion.py2rpy(v) --> 125 res = super(Function, self).call(*new_args, **new_kwargs) 126 res = conversion.rpy2py(res) 127 return res
~/anaconda3/envs/bayesian/lib/python3.7/site-packages/rpy2/rinterface_lib/conversion.py in _(*args, **kwargs) 42 def _cdata_res_to_rinterface(function): 43 def _(*args, **kwargs): ---> 44 cdata = function(*args, **kwargs) 45 # TODO: test cdata is of the expected CType 46 return _cdata_to_rinterface(cdata)
~/anaconda3/envs/bayesian/lib/python3.7/site-packages/rpy2/rinterface.py in call(self, *args, **kwargs) 622 error_occured)) 623 if error_occured[0]: --> 624 raise embedded.RRuntimeError(_rinterface._geterrmessage()) 625 return res 626
RRuntimeError: Error in unlink(f) : 3 arguments passed to .Internal(unlink) which requires 4
Hi Adam
I tested the following example of calling R from rpy2 and it worked (the code creates a plot)
import rpy2.robjects as robjects
r = robjects.r
x = robjects.IntVector(range(10)) y = r.rnorm(10)
r.X11()
r.layout(r.matrix(robjects.IntVector([1,2,3,2]), nrow=2, ncol=2)) r.plot(r.runif(10), y, xlab="runif", ylab="foo/bar", col="red")
I've installed r-base (3.6.1) and rpy2-3.3.6 - so I do not understand why installation of brms is not working - I now think it has to do with the R repositories
Hi Adam @adamhaber
An additional code I ran is the following code from rpy2 website and it did not work. I got the same error I have been getting as before:
import rpy2's package module import rpy2.robjects.packages as rpackages
import R's utility package utils = rpackages.importr('utils')
select a mirror for R packages utils.chooseCRANmirror(ind=1) # select the first mirror in the list
Main error R[write to console]: Warning: R[write to console]: failed to download mirrors file (long vectors not supported yet: libcurl.c:952); using local file '/home/user/anaconda3/envs/bayesian/lib/R/doc/CRAN_mirrors.csv'
R[write to console]: Error in unlink(f) : 3 arguments passed to .Internal(unlink) which requires 4
I tried one other piece of code from rpy2 website: same error @adamhaber
new code R package names packnames = ('ggplot2', 'brms')
R vector of strings from rpy2.robjects.vectors import StrVector
Selectively install what needs to be install. We are fancy, just because we can. names_to_install = [x for x in packnames if not rpackages.isinstalled(x)] if len(names_to_install) > 0: utils.install_packages(StrVector(names_to_install))
Error
R[write to console]: Warning: R[write to console]: failed to download mirrors file (long vectors not supported yet: libcurl.c:952); using local file '/home/user/anaconda3/envs/bayesian/lib/R/doc/CRAN_mirrors.csv'
R[write to console]: Error in unlink(f) : 3 arguments passed to .Internal(unlink) which requires 4
RRuntimeError Traceback (most recent call last)
~/anaconda3/envs/bayesian/lib/python3.7/site-packages/rpy2/robjects/functions.py in call(self, *args, **kwargs)
~/anaconda3/envs/bayesian/lib/python3.7/site-packages/rpy2/robjects/functions.py in call(self, *args, **kwargs)
~/anaconda3/envs/bayesian/lib/python3.7/site-packages/rpy2/rinterface_lib/conversion.py in _(*args, **kwargs)
~/anaconda3/envs/bayesian/lib/python3.7/site-packages/rpy2/rinterface.py in call(self, *args, **kwargs)
RRuntimeError: Error in unlink(f) : 3 arguments passed to .Internal(unlink) which requires 4
@adamhaber I noticed in the rpy2 website that it compiles using Python 3.5 and R 3.2+. See the link here:
https://rpy2.github.io/doc/v2.9.x/html/overview.html#background
See the section under Requirements
I'm working with Python 3.8 and Python 3.7.9 and I get the following inconsistency error when I run
conda install -c r rpy2
*Found conflicts! Looking for incompatible packages. This can take several minutes. Press CTRL-C to abort. failed
UnsatisfiableError: The following specifications were found to be incompatible with the existing python installation in your environment:
Specifications:
- rpy2 -> python[version='2.7.x|3.5.x|3.6.x|>=2.7,<2.8.0a0|>=3.5,<3.6.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0|3.4.x|3.3.*']
Your python: python=3.8
If python is on the left-most side of the chain, that's the version you've asked for. When python appears to the right, that indicates that the thing on the left is somehow not available for the python version you are constrained to. Note that conda will not change your python version to a different minor version unless you explicitly specify that.*
Could this be the source of errors I'm seeing? I'm curious since as I reported earlier, I can get rpy2 to work as long as I do not ask it to install any packages.
pip install rpy2 works and it does not give the unsatisfiable error, but it does not let me install brms or anyother package.
Thanks for running all these tests! Hopefully this will help in improving packaging/dependencies issues.
Could this be the source of errors I'm seeing? I'm curious since as I reported earlier, I can get rpy2 to work as long as I do not ask it to install any packages.
Not sure, these things can require a lot of trial-and-error sometimes... :-\ Especially with complicated dependencies like R and RPy2.
Can you try creating a new conda environment with Python 3.6?
pip uninstall pybrms
pip uninstall rpy2
conda create -n foo python=3.6
conda activate foo
conda install -c r r-base
conda install -c r rpy2
pip install pybrms
@adamhaber I'm doing that now. I will let you know how it proceeds
@adamhaber I just got these 2 errors towards the end of the installation process: I will still test it though and let you know. One is for pip and the other is for rpy2 and pybrms
*ERROR: After October 2020 you may experience errors when installing or updating packages. This is because pip will change the way that it resolves dependency conflicts.
We recommend you use --use-feature=2020-resolver to test your packages with the new resolver before it becomes the default.*
pybrms 0.0.31 requires rpy2>=3.1, but you'll have rpy2 2.9.4 which is incompatible.
I just tried
pip uninstall pybrms
pip uninstall rpy2
conda create -n foo python=3.6
conda activate foo
conda install -c r r-base
conda install -c r rpy2
pip install pybrms
conda installed RPy2 3.1.0, despite the fact that this site also lists v2.9.4, and I was able to use pybrms
. What happens if you try conda install -c r rpy2==3.1.0
?
EDIT: Two more suggestions/questions:
- What happens if, after
conda install -c r r-base
, you try topip install rpy2
? - Have you tried this? My guess is that it's not the reason (since you were able to call R in general), but might be worth trying.
@adamhaber By default conda installed rpy2 v-2.9.4. Then I used pip install rpy2 v-3.3.6 and pip deleted the old version and installed the new one. Sorry about some of the large bolded font. I do not how that happens to undo that. My apologies
I was able to execute the commands but the brms installation has gotten stuck with the inability to install "curl" package with the following error:
installing source package ‘curl’ ... package ‘curl’ successfully unpacked and MD5 sums checked using staged installation Found pkg-config cflags and libs! Using PKG_CFLAGS=-I/usr/include/x86_64-linux-gnu Using PKG_LIBS=-lcurl ------------------------- ANTICONF ERROR --------------------------- Configuration failed because libcurl was not found. Try installing: deb: libcurl4-openssl-dev (Debian, Ubuntu, etc) rpm: libcurl-devel (Fedora, CentOS, RHEL) csw: libcurl_dev (Solaris) If libcurl is already installed, check that 'pkg-config' is in your PATH and PKG_CONFIG_PATH contains a libcurl.pc file. If pkg-config is unavailable you can set INCLUDE_DIR and LIB_DIR manually via: R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
When I tried to run sudo apt install libcurl4-openssl-dev I got the following message
libcurl4-openssl-dev is already the newest version (7.68.0-1ubuntu2.2). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Searching on Stack Overflow users suggested that curl needs to be manually compiled if R in a conda environment is unable to recognize libcurl4 ( https://stackoverflow.com/questions/42115972/configuration-failed-because-libcurl-was-not-found )
So I used the code given there (I'm a beginner with Linux / Unix env)
sudo wget https://github.com/curl/curl/releases/download/curl-7_72_0/curl-7.72.0.tar.gz ./configure make make install
In the new environment in miniconda3 where I installed rpy2 I checked that the file libcurl.pc was present in the pkgconfig folder and it is, but I'm unable to install brms.
I can install all other packages that do not depend on curl but not V8, rsconnect, rstan, brms, shinystan that depend on curl
I'm stuck at this point now. Let me try what you suggested of conda rpy2 with request for version 3.1 - thanks again for your help
@adamhaber
I tried the steps to install rpy2==3.1.0 using conda - that installation worked but not the brms installation
Got the same curl CONFIG error - All those not dependent on curl were installed
Found pkg-config cflags and libs! Using PKG_CFLAGS=-I/usr/include/x86_64-linux-gnu Using PKG_LIBS=-lcurl ------------------------- ANTICONF ERROR --------------------------- Configuration failed because libcurl was not found. Try installing: deb: libcurl4-openssl-dev (Debian, Ubuntu, etc) rpm: libcurl-devel (Fedora, CentOS, RHEL) csw: libcurl_dev (Solaris) If libcurl is already installed, check that 'pkg-config' is in your PATH and PKG_CONFIG_PATH contains a libcurl.pc file. If pkg-config is unavailable you can set INCLUDE_DIR and LIB_DIR manually via: R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
I will test some more later
Have you tried conda install -c anaconda libcurl
?
Yes I have tried both anaconda curl and libcurl- still the same error persists
@adamhaber
I solved the curl error by adding the location of libcurl.pc in miniconda3 to the PKG_CONFIG_PATH and could install curl - Now I'm having issues with V8 package upon which all Stan based packages work. I will let you know more as I find the resolution
Wow, great work @sreedta8 ! I wonder to what extent are these issues OS-specific. Would be happy to hear if you make any progress with this.
@adamhaber I got pybrms working using r-base 3.6.1, rpy2-3.3.6, and python 3.6.10 on a Windows 10 Anaconda platform with some simple tweaks. I'm on the final steps of getting it to work on Ubuntu. Fingers-crossed and a few prayers under my breath. I will let you know how it goes. One thing is for sure: the installation for Windows and Ubuntu is very very different and it has to do with how the systems are setup. Making it work under Anaconda is also another big additional challenge. I will pull all of my notes together and send some thing to you so you add this to your site - Thank you so much!
Happy to hear that worked out for you, and thanks for all your efforts! I hope you'll find it useful. It's still in its infancy, so any feedback regarding actual usage (other than dependencies struggles) would be much appreciated.
@adamhaber I also got it working on Ubuntu with the help of @jeroen (Jeroen Ooms) who maintains the V8 library on GitHub. He had asked me to install r-v8 from conda-forge and that solved all the issues I faced with getting curl, V8 etc to work correctly in a conda environment on Ubuntu. Thanks for your help. Having you correspond and reading your input helped out a lot. In about a week, I will send the documentation that you can use / post here. I will be testing the pybrms for model evaluation and visualiztions with arviz next week. I will provide my feedback.
Sree