423 字
2 分钟
Resolving rpy2 Installation Permission Issues via Wheel Files

Background#

Recently, while trying to interface Python with R, I needed to install the rpy2 package. Installing it with pip in the usual way kept hitting all kinds of errors:

Terminal window
File "Z:\ProgramData\miniconda3\Lib\subprocess.py", line 1538, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [WinError 5] Access is denied
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.

There were various other problems too. Resetting R_HOME (https://www.cnblogs.com/Xeonilian/p/windows_rpy2_install.html), installing R_Tools (https://blog.csdn.net/BioFlorist/article/details/121665959), installing MinGW, and various other methods all failed to solve it. This problem plagued me for two full days, and no matter what I tried, it couldn’t be fixed. I even reached the point of suspecting that rpy2 doesn’t support Windows (on rpy2’s official website, it says Windows support is provided not by the official project but by the community), yet my classmate installed it successfully with ease.

The Solution#

After many failed attempts, some people online recommended installing with conda. But while that can install it, it uses the R environment installed by conda rather than my local R environment. A large number of R packages would need to be reinstalled. After searching for a long time, I found that I could bypass the compilation issue with precompiled wheel files. However, many tutorials online use the wheel packages hosted at www.lfd.uci.edu, but the professor who maintained that hosting site has shut it down due to server costs and no longer hosts rpy2. Later, after some searching, I found precompiled rpy2 wheel files on the piwheels website. There aren’t many wheel versions available - the latest stable 3.5.17 isn’t there either, only the 3.6.0.dev2 pre-release. But having something is still much better than nothing.

Additionally, the official website has some compatibility info between R and rpy2.

Installation Steps#

  1. Visit piwheels
  2. Find the corresponding wheel file according to your Python version
  3. Download the wheel file locally
  4. Open the command line and install using the following command:
Terminal window
pip install 你下载的wheel文件路径

Installation Notes#

Before installing, make sure the R language environment is properly configured on your system, because rpy2 needs to call R’s library files.

Summary#

When pip fails to compile rpy2, you can try searching www.piwheels.org for a precompiled wheel file. Although the process was a bit tortuous, I hope my experience can help those of you facing similar problems and save you some detours.

Resolving rpy2 Installation Permission Issues via Wheel Files
https://tski.uk/blog/en/rpy2-install-via-wheel/
作者
Tokisaki Galaxy
发布于
2025-02-27
许可协议
CC BY