Error When Installing Rpy2 Module in Python with Easy_Install

Error when installing rpy2 module in Python with easy_install

There's a much easier way to go about this - install rpy2 from Christoph Gohlke's Python Extension Packages for Windows repository here. Download the rpy2‑2.5.5‑cp34‑none‑win_amd64.whl file (the current version at the time of this writing), change to the download folder on the command line, and run

pip install rpy2‑2.5.5‑cp34‑none‑win_amd64.whl

pip is already included in Python 3.4, and should be used instead of easy_install when installing new modules, as easy_install is deprecated.

How can I install gekko package using R reticulate?

A more general answer for help in similar cases:

  1. Install gekko and other packages in a new environment in R.
reticulate::py_install(
packages = c(
"gekko",
"other_package==x.x.x", # It's possible to specify the package version
...
),
envname = "new_env",
method = "conda", # For Windows
python_version = "3.x.x",
pip = TRUE
)

  1. Call reticulate package using the new environment.
Sys.setenv(RETICULATE_PYTHON = "/Users/user_name/anaconda#/envs/new_env/python.exe")
library(reticulate)

  1. Run your Python script with gekko in R.
source_python("path/script.py")

Using rpy2: cannot find R package that is installed

Okay, it was a pretty stupid thing:

R installs my packages at two locations on my computer: in an R folder in the Documents and in the actual program folder in Program Files. You can check your locations like this:

> .libPaths()
[1] "C:/Users/XYZ/Documents/R/win-library/3.6"
[2] "C:/Program Files/R/R-3.6.3/library"

rpy2 was only able to use the packages that were installed in location [2].

I simply moved everything from [1] to [2]. Now it works!

Installing rpy2

If you're desperate, you could install WinPython (for windows users) which has a lot of Packages already installed and ready to use, including rpy2, sometimes installing packages on windows can be stressful.

Or if you really want to make it work that way, maybe you could check if that package was installed in the Downloads folder and move it to the folder corresponding to python libraries



Related Topics



Leave a reply



Submit