1

I can't install gekko package via R reticulate. My R version is 3.4.4 and my Python version is 3.8.8 and I use Gekko in Python without problems. So I tried to install on R in these two ways I know:

  1. py_install("gekko")

  2. reticulate::conda_install("my_conda_environment", "gekko")

However in both cases I receive the same error bellow.

PackagesNotFoundError: The following packages are not available from current channels:

  • gekko

Current channels:

I didn't find other alternatives in the Anaconda documentation. How can I fix this?

Edit: I solved my problem based on the references in John Hedengren's answer and reticulate docs. For that, I needed to create a new environment to specify the Python version and packages using the following code in R:

reticulate::py_install(
    packages = c(
        "numpy",  
        "pandas", # Or another packages that you need
        "gekko"
    ),
    envname  = "r-gekko",
    method = "conda", # On Windows, the 'conda' method is always used
    python_version = "3.8.8",
    pip = TRUE # It's mandatory to install gekko
)

2 Answers2

2

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")
1

Gekko is available from pypi.org with pip install gekko and is not available with the conda package manager with conda install gekko. Here is more information on how to install Python packages with pip. You likely already know this because you are using gekko in Python but I've included it here for some background in case others need it.

Two potential problems are:

  • There are multiple Python versions installed and gekko is not installed for the version that is used with R.
  • Reticulate is not using PyPi repositories to install gekko. Here is additional information on managing the source (either Conda or PyPi) to retrieve the packages.

I'm not familiar with R but there are others that have similar questions such as:

John Hedengren
  • 12,068
  • 1
  • 21
  • 25