r-lib / actions

GitHub Actions for the R community
Creative Commons Zero v1.0 Universal
963 stars 209 forks source link

rpy2 cannot find R installation on Ubuntu or Windows (works fine on macOS) #124

Closed loikein closed 4 years ago

loikein commented 4 years ago

Describe the bug

Using R with rpy2, these are my action suite: (I found the LD_LIBRARY_PATH from some online answer, which didn't work)

jobs:
  run-tests:
    name: Run tests for ${{ matrix.os }} on ${{ matrix.python-version }}
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
        python-version: ['3.7']

    steps:
    - uses: actions/checkout@v2

    - uses: r-lib/actions/setup-R@v1
      with:
          r-version: '4.0.1'

    - uses: goanpeca/setup-miniconda@v1.0.2
      with:
          auto-update-conda: true
          activate-environment: econsa
          environment-file: environment.yml
          python-version: ${{ matrix.python-version }}

    - name: Run test suite.
      shell: bash -l {0}
      env:
        LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}:/usr/lib/R/lib
      run: |
        pytest --cov=econsa --cov-report=xml

rpy2 is installed with environment.yml and pip, which succeeded.

During Run test suite, error message under Windows:

=================================== ERRORS ====================================
_______________ ERROR collecting econsa/tests/test_sampling.py ________________
econsa\tests\test_sampling.py:7: in <module>
    import rpy2.robjects.packages as rpackages
C:\Miniconda\envs\econsa\lib\site-packages\rpy2\robjects\__init__.py:16: in <module>
    import rpy2.rinterface as rinterface
C:\Miniconda\envs\econsa\lib\site-packages\rpy2\rinterface.py:6: in <module>
    from rpy2.rinterface_lib import openrlib
C:\Miniconda\envs\econsa\lib\site-packages\rpy2\rinterface_lib\openrlib.py:44: in <module>
    rlib = _dlopen_rlib(R_HOME)
C:\Miniconda\envs\econsa\lib\site-packages\rpy2\rinterface_lib\openrlib.py:37: in _dlopen_rlib
    rlib = ffi.dlopen(lib_path)
E   OSError: cannot load library 'C:\R\bin\x64\R.dll': error 0x7e

Error message under Ubuntu:

==================================== ERRORS ====================================
________________ ERROR collecting econsa/tests/test_sampling.py ________________
econsa/tests/test_sampling.py:7: in <module>
    import rpy2.robjects.packages as rpackages
/usr/share/miniconda/envs/econsa/lib/python3.7/site-packages/rpy2/robjects/__init__.py:19: in <module>
    from rpy2.robjects.robject import RObjectMixin, RObject
/usr/share/miniconda/envs/econsa/lib/python3.7/site-packages/rpy2/robjects/robject.py:58: in <module>
    class RObjectMixin(object):
/usr/share/miniconda/envs/econsa/lib/python3.7/site-packages/rpy2/robjects/robject.py:70: in RObjectMixin
    __show = _get_exported_value('methods', 'show')
/usr/share/miniconda/envs/econsa/lib/python3.7/site-packages/rpy2/rinterface_lib/conversion.py:44: in _
    cdata = function(*args, **kwargs)
/usr/share/miniconda/envs/econsa/lib/python3.7/site-packages/rpy2/rinterface.py:624: in __call__
    raise embedded.RRuntimeError(_rinterface._geterrmessage())
E   rpy2.rinterface_lib.embedded.RRuntimeError: Error in dyn.load(file, DLLpath = DLLpath, ...) : 
E     unable to load shared object '/opt/R/4.0.1/lib/R/library/methods/libs/methods.so':
E     libR.so: cannot open shared object file: No such file or directory
------------------------------- Captured stderr --------------------------------
##[error]Error: package or namespace load failed for ‘methods’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/opt/R/4.0.1/lib/R/library/methods/libs/methods.so':
  libR.so: cannot open shared object file: No such file or directory
##[error]Error: package or namespace load failed for ‘grDevices’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/opt/R/4.0.1/lib/R/library/grDevices/libs/grDevices.so':
  libR.so: cannot open shared object file: No such file or directory
##[error]Error: package or namespace load failed for ‘graphics’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/opt/R/4.0.1/lib/R/library/grDevices/libs/grDevices.so':
  libR.so: cannot open shared object file: No such file or directory
##[error]Error: package or namespace load failed for ‘stats’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/opt/R/4.0.1/lib/R/library/grDevices/libs/grDevices.so':
  libR.so: cannot open shared object file: No such file or directory
##[error]Error: package or namespace load failed for ‘methods’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/opt/R/4.0.1/lib/R/library/methods/libs/methods.so':
  libR.so: cannot open shared object file: No such file or directory
During startup - Warning messages:
1: package ‘utils’ in options("defaultPackages") was not found 
2: package ‘grDevices’ in options("defaultPackages") was not found 
3: package ‘graphics’ in options("defaultPackages") was not found 
4: package ‘stats’ in options("defaultPackages") was not found 
5: package ‘methods’ in options("defaultPackages") was not found 

To Reproduce

Bug logging: https://github.com/OpenSourceEconomics/econsa/pull/33/checks?check_run_id=800600525 Code to test: https://github.com/OpenSourceEconomics/econsa/blob/conditional-sampler/econsa/tests/test_sampling.py CI scrirpt: https://github.com/OpenSourceEconomics/econsa/blob/conditional-sampler/.github/workflows/continuous-integration-workflow.yml

Expected behavior

Since this action did not specify OS, I expected it to work for all OS's.

jimhester commented 4 years ago

Sorry, I don't have the resources to debug conda issues, and I don't know anything about rpy2.

I think likely your issue is from those packages failing to find the R shared libraries on your library path, but you will have to open an issue in other venues if you cannot determine the remedy yourself.

loikein commented 4 years ago

Thank you so much for your attention. Sorry for my unfamilarity with GitHub actions. Would you be able to tell me the path of R installations that this action is using, or how to find out that?

jimhester commented 4 years ago

Maybe you can look at the workflows in the rpy2 repo (https://github.com/rpy2/rpy2/blob/07f5fbeb117588b82c0bb83c1cc0c5411d311e93/.github/workflows/pythonpackage.yml#L47), they seem to be using the setup-r action from here there on Windows, macOS and ubuntu.

loikein commented 4 years ago

I see… I will take a look at their workflow. Thank you again!

loikein commented 4 years ago

Hi, I tried rpy2's code of LD_LIBRARY_PATH on Ubuntu, and it worked.

But on Windows, when I run python -m rpy2.situation, it appears that R is not added to PATH. Would you like to take a look at the action again?

rpy2 version:
3.3.4
Python version:
3.7.7 (default, May  6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)]
Looking for R's HOME:
    Environment variable R_HOME: None
    InstallPath in the registry: C:\R
    Environment variable R_USER: None
    Environment variable R_LIBS_USER: d:\a\_temp\Library
R version:
    In the PATH: None
    Loading R library from rpy2: cannot load library 'C:\R\bin\x64\R.dll': error 0x7e
Additional directories to load R packages from:
None
C extension compilation:
  include:
  ['C:/R/include', 'C:/R/include/x64']
  libraries:
  ['R', 'm']
  library_dirs:
  ['C:/R/bin/x64']
  extra_compile_args:
  []
  extra_link_args:
  []
loikein commented 4 years ago

I think it's a problem with rpy2 implementation on Windows, and I will make an issue there. Thank you for your patience.

jake-lester commented 3 years ago

having same issue.

MLopez-Ibanez commented 2 years ago

me too, and I cannot find the solution.

github-actions[bot] commented 1 year ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue and include a link to this issue