Search code examples
pythonranacondagekkoreticulate

How can I install gekko package using R reticulate?


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
)

Solution

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