1. rpy2
  2. rpy2
  3. rpy2
  4. Issues

Issues

Issue #265 invalid

Windows- Error in loadNamespace

lampkld
created an issue

Hello,

I'm trying to load the 'mi' package after successful installation in R, but i receive the following error:

RRuntimeError: Error in loadNamespace(name) : there is no package called 'mi'

What can I do to fix this please?

Thanks

Supporting information:

Python 2.7.8, Windows 7 64

R

> loadNamespace('mi')
<environment: namespace:mi>

Python

import rpy2.rinterface
rpy2.rinterface.set_initoptions(('rpy2', '--verbose', '--no-save'))

from rpy2.robjects.packages import importr
mi = importr("mi")


---------------------------------------------------------------------------
RRuntimeError                             Traceback (most recent call last)
<ipython-input-2-6c9d60c71efd> in <module>()
      1 from rpy2.robjects.packages import importr
----> 2 mi = importr("mi")

C:\Anaconda\lib\site-packages\rpy2\robjects\packages.pyc in importr(name, lib_loc, robject_translations, signature_translation, suppress_messages, on_conflict, data)
    397     if _package_has_namespace(rname, 
    398                               _system_file(package = rname)):
--> 399         env = _get_namespace(rname)
    400         version = _get_namespace_version(rname)[0]
    401         exported_names = set(_get_namespace_exports(rname))

RRuntimeError: Error in loadNamespace(name) : there is no package called 'mi'

Comments (14)

  1. Laurent Gautier

    This is very likely caused by having (at least) 2 different installations of R on your system: one with the package "mi" installed, and one without. The latter is the one picked up by you Python/rpy2 environment.

    Compare the two following paths:

    R:

    R.home()
    

    Python:

    from rpy2.robjects.packages import importr
    base = importr('base')
    print(base.R_home())
    
  2. lampkld reporter

    Thanks for the suggestion. Here are the results:

    R:

    > R.home()
    [1] "C:/PROGRA~1/R/R-31~1.2"
    

    Python:

    import rpy2.rinterface
    rpy2.rinterface.set_initoptions(('rpy2', '--verbose', '--no-save'))
    
    from rpy2.robjects.packages import importr
    base = importr('base')
    print(base.R_home())
    
    
    Unable to unlink tempfile c:\users\user\appdata\local\temp\tmpowly0f
    [1] "C:/Program Files/R/R-3.1.2"
    

    Edit: I seem to be getting the unlinking error mentioned here: https://bitbucket.org/rpy2/rpy2/issue/191/unable-to-unlink-file

    Any chance I can implement the fix from the REPL without having to rebuild rpy2? I'm working from a binary.

  3. Laurent Gautier

    lampkld Issue #191 is the subject of a proposed patch, but the Windows users are remarkably silent about whether it is solving the issue or not. Since it does not break anything on Linux it will make it to rpy2-2.5.6 (and we'll see what happens).

  4. lampkld reporter

    Laurent Gautier Thanks very much for working with me on this.

    Output as follows:

    R:

    > .libPaths()
    [1] "C:/Users/User/Documents/Me/R/win-library/3.1" "C:/Program Files/R/R-3.1.2/library" 
    

    Python:

    In [35]: print(base._libPaths())
    
    Unable to unlink tempfile c:\users\user\appdata\local\temp\tmpeq6rqu
    [1] "C:/Program Files/R/R-3.1.2/library"
    
  5. Laurent Gautier

    So both are running under different environment, with one looking for packages in 2 different directories (standalone R) and the other in only one directory (embedded R through rpy2).

    The causes for this can be multiple (e.g., configuration of an R IDE, definition of the variable R_LIBS in your launcher, etc...) and this is beyond the scope of rpy2's issue tracker.

    One workaround is to tell rpy2's importr where is the library:

    mi = importr("mi", lib_loc = "C:/Users/User/Documents/Me/R/win-library/3.1")
    
  6. lampkld reporter

    Laurent Gautier

    So pointing Rpy2 to the right location (confirmed by a visual search of the directory) fails as well:

    In [2]: from rpy2.robjects.packages import importr
    base = importr('base')
    mi = importr('mi', lib_loc="C:/Users/User/Documents/Me/R/win-library/3.1")
    
    
    ---------------------------------------------------------------------------
    RRuntimeError                             Traceback (most recent call last)
    <ipython-input-2-5ba7acb90c9e> in <module>()
          1 from rpy2.robjects.packages import importr
          2 base = importr('base')
    ----> 3 mi = importr('mi', lib_loc="C:/Users/User/Documents/Me/R/win-library/3.1")
    
    C:\Anaconda\lib\site-packages\rpy2\robjects\packages.pyc in importr(name, lib_loc, robject_translations, signature_translation, suppress_messages, on_conflict, data)
        397     if _package_has_namespace(rname, 
        398                               _system_file(package = rname)):
    --> 399         env = _get_namespace(rname)
        400         version = _get_namespace_version(rname)[0]
        401         exported_names = set(_get_namespace_exports(rname))
    
    RRuntimeError: Error in loadNamespace(name) : there is no package called 'mi'
    

    When I point directly to 'C:/Users/User/Documents/Me/R/win-library/3.1\mi', the kernel crashes.

  7. Laurent Gautier

    Using importr's lib_loc is not used frequently (at least not to my knowledge), so I can't rule out an issue there, but the code in rpy2 is quite simple and that parameter is passed right away to the underlying R function (so it should work).

    Regarding the kernel (!? you are on Windows - or may be you are using ipython ?) crash, this is not expected either.

    Windows is not officially supported so I will not be able to help you much further. May be try to install that "mi" package into R's main directory for packages ?

  8. gordon

    Hi Laurent,

    I am trying to solve an issue almost similar to this one : with the package egcm. rpy2 works fine in Spyder but I can't import the R package using : egcm = importr('egcm')

    My error is :

    File "C:\Users\My Name\Anaconda3\lib\site-packages\rpy2\robjects\packages.py", line 453, in importr env = _get_namespace(rname) RRuntimeError

    I have Python 3.5.2 |Anaconda 4.2.0 (64-bit)|

    Merdi d'avance pour votre aide!

  9. MichaelaR90

    I had a similar problem with EMMIXskew on WIndows using Spyder through Anaconda. Lib_loc didn't work for me but I found that the folder in which Syder was looking was different to the folder in which the install R files were stored. Complete cheat method but it worked was to just copy the folders (the method and the dependencies) from the R folder to the folder in which Sypder was looking.

  10. abarberan

    I have the same issue in a Ubuntu distribution. "Mice" library not found (installed but not found by rpy2)

    Solve follows @MichaleaR90 recomendation:

    .libPaths()

    [1] "/home/ubuntu/R/x86_64-pc-linux-gnu-library/3.2

    [2] "/usr/local/lib/R/site-library"
    [3] "/usr/lib/R/site-library"
    [4] "/usr/lib/R/library"

    search the location where 'mice' is installed:

    [1] "/home/ubuntu/R/x86_64-pc-linux-gnu-library/3.2"

    Copy to all other location where "mice" is NOT installed. One by one at time.

    cp -r /home/ubuntu/R/x86_64-pc-linux-gnu-library/3.2/mice /usr/lib/R/library/

    try to run my proccess again

    problem solved. ¬¬' ...

    --------------------------------------------------------------------------------

    Mismo problema en un Ubuntu. La libreria de R, "Mice", no era encontrada (Instalada pero no encontrada por rpy2

    Solucionado usando la recomendación de @MichaleaR90:

    .libPaths()

    [1] "/home/ubuntu/R/x86_64-pc-linux-gnu-library/3.2"

    [2] "/usr/local/lib/R/site-library"
    [3] "/usr/lib/R/site-library"
    [4] "/usr/lib/R/library"

    busque visualmente el directorio donde 'mice' sí esta instalado:

    [1] "/home/ubuntu/R/x86_64-pc-linux-gnu-library/3.2"

    Copié a todos los otros directorios donde "mice" NO esta instalado: Uno a la vez:

    cp -r /home/ubuntu/R/x86_64-pc-linux-gnu-library/3.2/mice /usr/lib/R/library/

    Ejecuté mi proceso de nuevo antes de copiar al siguiente (prueba y error):

    problema resuelto

  11. Log in to comment