Issue with rpy2 on windows.

0 views
Skip to first unread message

Alexander

unread,
Oct 1, 2016, 12:53:12 AM10/1/16
to Anaconda - Public
I installed rpy2 from the following package: https://anaconda.org/r/rpy2. However, I'm running into errors when importing; it looks like Windows is unable to find all of the necessary DLLs:

>>> from rpy2 import rinterface
C:\Users\Alexander\Anaconda3\R
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Alexander\Anaconda3\lib\site-packages\rpy2\rinterface\__init__.py", line 88, in <module>
    _load_r_dll(R_HOME)
  File "C:\Users\Alexander\Anaconda3\lib\site-packages\rpy2\rinterface\__init__.py", line 65, in _load_r_dll
    ctypes.CDLL(r_dll)
  File "C:\Users\Alexander\Anaconda3\lib\ctypes\__init__.py", line 347, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

When I tried loading the R DLL manually, I got the same error as well:

>>> path = "C:/Users/Alexander/Anaconda3/R/bin/x64/R.dll"
>>> ctypes.CDLL(path)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Alexander\Anaconda3\lib\site-packages\rpy2\rinterface\__init__.py", line 88, in <module>
    _load_r_dll(R_HOME)
  File "C:\Users\Alexander\Anaconda3\lib\site-packages\rpy2\rinterface\__init__.py", line 65, in _load_r_dll
    ctypes.CDLL(r_dll)
  File "C:\Users\Alexander\Anaconda3\lib\ctypes\__init__.py", line 347, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

Has anyone run into this same problem, and if so, has a way to fix it? One possible issue I've thought of is that I have a non-Anaconda version of R installed in Program Files. Could this possibly be confusing the OS, as for which path to look for DLLs?

Ian Stokes Rees

unread,
Oct 1, 2016, 6:15:43 PM10/1/16
to anac...@continuum.io

Hi Alexander,

I've reported this issue here: https://github.com/ContinuumIO/anaconda-issues/issues/1129

I can confirm I get exactly the same error on Windows 10 with Anaconda3 (v4.2.0) installed into my user directory.  I cannot see any way to fix this.  I believe that will make this a priority issue for the Anaconda team to address in the coming week or two.  I'd watch that issue above for progress (and give it a +1 if you want it to have extra attention!).

In [2]: from rpy2 import rinterface
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-2-40203d26f554> in <module>()
----> 1 from rpy2 import rinterface

C:\Users\ijsto\Anaconda3\lib\site-packages\rpy2\rinterface\__init__.py in <module>()
     85 
     86 if sys.platform == 'win32':
---> 87     _load_r_dll(R_HOME)
     88 
     89 # cleanup the namespace

C:\Users\ijsto\Anaconda3\lib\site-packages\rpy2\rinterface\__init__.py in _load_r_dll(r_home)
     62     if r_bin not in os.environ.get('PATH'):
     63         os.environ['PATH'] = ';'.join((os.environ.get('PATH'), r_bin, r_mod))
---> 64     ctypes.CDLL(r_dll)
     65 
     66 

C:\Users\ijsto\Anaconda3\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
    345 
    346         if handle is None:
--> 347             self._handle = _dlopen(self._name, mode)
    348         else:
    349             self._handle = handle

OSError: [WinError 126] The specified module could not be found

I also tried uninstalling the Conda version of rpy2, and then attempted a pip install of rpy2, but no luck there either (I think for different reasons).  Here is the GH issue reporting this:

```

C:\Users\ijsto>pip install rpy2
Collecting rpy2
  Downloading rpy2-2.8.3.tar.gz (186kB)
    100% |################################| 194kB 84kB/s
    Complete output from command python setup.py egg_info:


    Traceback (most recent call last):

      File "<string>", line 1, in <module>
      File "C:\Users\ijsto\AppData\Local\Temp\pip-build-kirh2vv0\rpy2\setup.py", line 331, in <module>
        ri_ext = getRinterface_ext()
      File "C:\Users\ijsto\AppData\Local\Temp\pip-build-kirh2vv0\rpy2\setup.py", line 234, in getRinterface_ext
        if rexec.version[0] == 'development' or \
      File "C:\Users\ijsto\AppData\Local\Temp\pip-build-kirh2vv0\rpy2\setup.py", line 160, in version
        universal_newlines = True)
      File "C:\Users\ijsto\Anaconda3\lib\subprocess.py", line 626, in check_output
        **kwargs).stdout
      File "C:\Users\ijsto\Anaconda3\lib\subprocess.py", line 708, in run
        output=stdout, stderr=stderr)
    subprocess.CalledProcessError: Command '('C:\\Users\\ijsto\\Anaconda3\\R\\bin\\x64\\R', '--version')' returned non-zero exit status 3221225781

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\ijsto\AppData\Local\Temp\pip-build-kirh2vv0\rpy2\
```

Regards,

Ian

Ray

unread,
Oct 3, 2016, 7:37:08 AM10/3/16
to Anaconda - Public, alexande...@college.harvard.edu

The problem happens because environments are not activated in the python script that menuinst uses to execute conda-installed sotware: https://github.com/ContinuumIO/menuinst/blob/master/cwp.py  Changing that part of cwp.py to the following:


env = os.environ.copy()
env['PATH'] = os.path.pathsep.join([
        prefix,
        join(prefix, "Scripts"),
        join(prefix, "Library", "bin"),
        join(prefix, "Library", "mingw-w64", "bin"),
        env['PATH'],
])
.. avoids this bug. You will most likely find that file in `%UserProfile%\Anaconda3\cwp.py` if you wish to try it out. I hope to discuss the best fix for this at https://github.com/ContinuumIO/anaconda-issues/issues/1129

Best,

Ray.

Ray

unread,
Oct 5, 2016, 4:42:21 PM10/5/16
to Anaconda - Public, alexande...@college.harvard.edu
This is now fixed. To get the fix, please enter:

conda update menuinst

.. from the Anaconda Prompt.



On Saturday, October 1, 2016 at 5:53:12 AM UTC+1, Alexander wrote:

alexande...@college.harvard.edu

unread,
Oct 5, 2016, 4:50:52 PM10/5/16
to Anaconda - Public, alexande...@college.harvard.edu
Hmm, still not working for me. I also tried uninstalling and reinstalling rpy2 after updating menuinst, to no avail.

ray.do...@gmail.com

unread,
Oct 5, 2016, 4:58:03 PM10/5/16
to Anaconda - Public
How are you launching Python?

Alexander Whatley

unread,
Oct 5, 2016, 5:23:52 PM10/5/16
to anac...@continuum.io
From the terminal:

C:\Users\Alexander>python
Python 3.5.1 |Anaconda custom (64-bit)| (default, Feb 16 2016, 09:49:46) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import menuinst
>>> menuinst.__version__
'1.4.2'
>>> import rpy2
>>> rpy2.__version__
'2.8.2'
>>> from rpy2 import rinterface
C:\Users\Alexander\Anaconda3\R
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Alexander\Anaconda3\lib\site-packages\rpy2\rinterface\__init__.py", line 88, in <module>
    _load_r_dll(R_HOME)
  File "C:\Users\Alexander\Anaconda3\lib\site-packages\rpy2\rinterface\__init__.py", line 65, in _load_r_dll
    ctypes.CDLL(r_dll)
  File "C:\Users\Alexander\Anaconda3\lib\ctypes\__init__.py", line 347, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

On Wed, Oct 5, 2016 at 4:58 PM, <ray.do...@gmail.com> wrote:
How are you launching Python?

--
Anaconda Community Support Group Brought to you by Continuum Analytics
---
You received this message because you are subscribed to a topic in the Google Groups "Anaconda - Public" group.
To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/anaconda/Rt0wvugxr2Y/unsubscribe.
To unsubscribe from this group and all its topics, send an email to anaconda+unsubscribe@continuum.io.
To post to this group, send email to anac...@continuum.io.
Visit this group at https://groups.google.com/a/continuum.io/group/anaconda/.

ray.do...@gmail.com

unread,
Oct 5, 2016, 5:46:50 PM10/5/16
to Anaconda - Public
Please try with the Anaconda Prompt from the start menu instead.

Alexander Whatley

unread,
Oct 5, 2016, 8:33:18 PM10/5/16
to anac...@continuum.io
It appears to work from the Anaconda Prompt. Thanks for your help. Any ideas why it doesn't work from the regular command prompt though?

On Wed, Oct 5, 2016 at 5:46 PM, <ray.do...@gmail.com> wrote:
Please try with the Anaconda Prompt from the start menu instead.

ray.do...@gmail.com

unread,
Oct 6, 2016, 1:57:44 AM10/6/16
to Anaconda - Public
Yes. The Add to PATH option in the installer needs to add an additional entry. Fixing that requires new installers to be built.

But also, conda has the concept of environment activation and deactivation and *not* using the Anaconda Prompt slips that stuff unfortunately. You can read a detailed discussion at:

https://github.com/ContinuumIO/anaconda-issues/issues/1129

saje...@gmail.com

unread,
Aug 20, 2017, 2:37:39 AM8/20/17
to Anaconda - Public, ray.do...@gmail.com
Hi,

I have tried the solution suggested above: conda update menuinst. I ran this from the Anaconda command prompt that I got from Start Menu. But I still get the following error:


Traceback (most recent call last):
  File "C:\Users\Sajeev\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-4-925d2536d534>", line 1, in <module>
    from rpy2.robjects import r,pandas2ri
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.1.2\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\Sajeev\Anaconda3\lib\site-packages\rpy2\robjects\__init__.py", line 16, in <module>
    import rpy2.rinterface as rinterface
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.1.2\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\Sajeev\Anaconda3\lib\site-packages\rpy2\rinterface\__init__.py", line 87, in <module>
    _load_r_dll(R_HOME)
  File "C:\Users\Sajeev\Anaconda3\lib\site-packages\rpy2\rinterface\__init__.py", line 64, in _load_r_dll
    ctypes.CDLL(r_dll)
  File "C:\Users\Sajeev\Anaconda3\lib\ctypes\__init__.py", line 344, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

Is there anything else that I should do?

Thanks

Ray Donnelly

unread,
Aug 20, 2017, 6:33:16 AM8/20/17
to Anaconda - Public
You ran that from PyCharm by the look of it?

--
Anaconda Community Support Group Brought to you by Continuum Analytics
---
You received this message because you are subscribed to the Google Groups "Anaconda - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to anaconda+unsubscribe@continuum.io.

L. Jin

unread,
Aug 10, 2019, 5:30:41 PM8/10/19
to Anaconda - Public
Finally found someone running into the same issue. I try to load "conda update menuinst" from anaconda prompt, still no luck. the same WinError 126 appears. So annoying. Don't know what to do now. I also tried to uninstall and reinstall anaconda, by the way.
To unsubscribe from this group and stop receiving emails from it, send an email to anac...@continuum.io.
Reply all
Reply to author
Forward
0 new messages