简体   繁体   中英

Errors like "cons memory exhausted" while import rpy2

I am using PyCharm and try to import rpy2 (version 3.3.5) with the following code:

import numpy as np
import pandas as pd
import rpy2.robjects.packages as packages

print("TEST")

I get the following error:

R[write to console]: Error: cons memory exhausted (limit reached?)

R[write to console]: Error: no more error handlers available (recursive errors?); invoking 'abort' restart


Process finished with exit code -1073741784 (0xC0000028)

I am using Windows 10, have 16GB RAM available.

I have run into the same issue and after extensive research and a lot of trial and error, I have two solutions:

  1. If you can use a Jupyter notebook (even in Pycharm), the cons memory exhausted error will not happen when importing rpy2 modules.

  2. If you need to use the Python console in Pycharm when running your code importing rpy2 modules and want to avoid this error, there is a workaround I use. I noticed that this error may happen due to an active renv environment set up for R in the same project. When R is set up in the same project with Python together with renv dependency management, there is a.Rprofile file in the root folder to activate renv for new R sessions. When the code is not executed (eg commented out) when importing an rpy2 module then there is no memory exhaust error. Once the rpy2 module is imported, renv can be activated again and all rpy2 code will execute as normal. Moreover, rpy2 can be directed to the renv environment to use packages from R project dependencies. To summarise the steps to the workaround, I wrote a function that: 1. opens.Rprofile and comments out all code 2. using Python's importlib I import the necessary rpy2 module 3. set the R_LIBS_USER environment variable to the path of the renv library path 4. remove the commenting from.Rprofile file. I will put this code on my Github later.

尝试删除目录中由 RStudio 生成的所有文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM