rpy2 / rpy2

Interface to use R from Python
https://rpy2.github.io
GNU General Public License v2.0
552 stars 73 forks source link

rpy2 cannot resolve the correct on Mac M1 #1099

Open Antidington opened 6 months ago

Antidington commented 6 months ago

Hi all,

When I load the Lib path with custom configuration /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library, rpy2 incorrectly parses the path /Library/Frameworks/R.framework/Versions/4.2-arm64/R/bin/Rscript.

The following is the output of command python -m rpy2.situation.

python -m rpy2.situation
rpy2 version:
3.5.2
Python version:
3.10.13 | packaged by conda-forge | (main, Dec 23 2023, 15:35:25) [Clang 16.0.6 ]
Looking for R's HOME:
    Environment variable R_HOME: /Library/Frameworks/R.framework/Versions/4.2-arm64/R
    Calling `R RHOME`: /opt/homebrew/Caskroom/mambaforge/base/envs/scToolkits/lib/R
    Environment variable R_LIBS_USER: None
    Warning: The environment variable R_HOME differs from the default R in the PATH.
R's additions to LD_LIBRARY_PATH:
rpy2.situation: Unable to determine R library path: [Errno 20] Not a directory: '/Library/Frameworks/R.framework/Versions/4.2-arm64/R/bin/Rscript'

Unable to determine R library path: [Errno 20] Not a directory: '/Library/Frameworks/R.framework/Versions/4.2-arm64/R/bin/Rscript'
R version:
    In the PATH: R version 4.2.3 (2023-03-15) -- "Shortstop Beagle"
    Loading R library from rpy2: OK
Additional directories to load R packages from:
None
C extension compilation:
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/scToolkits/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/scToolkits/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/scToolkits/lib/python3.10/site-packages/rpy2/situation.py", line 435, in <module>
    for row in iter_info():
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/scToolkits/lib/python3.10/site-packages/rpy2/situation.py", line 389, in iter_info
    c_ext.add_lib(*get_r_flags(r_home, '--ldflags'))
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/scToolkits/lib/python3.10/site-packages/rpy2/situation.py", line 252, in get_r_flags
    _get_r_cmd_config(r_home, flags,
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/scToolkits/lib/python3.10/site-packages/rpy2/situation.py", line 217, in _get_r_cmd_config
    output = subprocess.check_output(
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/scToolkits/lib/python3.10/subprocess.py", line 421, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/scToolkits/lib/python3.10/subprocess.py", line 503, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/scToolkits/lib/python3.10/subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/scToolkits/lib/python3.10/subprocess.py", line 1863, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
NotADirectoryError: [Errno 20] Not a directory: '/Library/Frameworks/R.framework/Versions/4.2-arm64/R/bin/R'

Is there any solutions?

Thanks! Jichen

lgautier commented 6 months ago
Environment variable R_HOME: /Library/Frameworks/R.framework/Versions/4.2-arm64/R

You seem to have an environment variable R_HOME defined, and its content be invalid (not an R HOME location).

Unset it (see below), and try again.

unset R_HOME