Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in GitHub Action Virtualenv_create with R-devel and Reticulate #1544

Closed
pbulsink opened this issue Mar 5, 2024 · 15 comments · Fixed by #1667
Closed

Error in GitHub Action Virtualenv_create with R-devel and Reticulate #1544

pbulsink opened this issue Mar 5, 2024 · 15 comments · Fixed by #1667

Comments

@pbulsink
Copy link

pbulsink commented Mar 5, 2024

Hello, we have a recurrent error with reticulate for rdevel on ubuntu in our github action:

https://github.com/SCasanova/f1dataR/actions/runs/8149812048/job/22275075253

In particular, trying to create a virtualenv causes the following error:

Error in .make_numeric_version(x, strict, .standard_regexps()$valid_numeric_version) : 
  invalid non-character version specification 'x' (type: double)
Calls: virtualenv_create ... as.numeric_version -> numeric_version -> .make_numeric_version

Other versions of R on the same platform (release and oldrel) and with specified (3.11) or generic (3.x) versions of python pass.
R-Devel on other platforms (windows-latest/macos-latest) with specified (3.11) or generic (3.x) versions of python fail.

Code suffering the error:

      - name: setup r-reticulate venv
        shell: Rscript {0}
        run: |
          python_packages <- c("numpy", "fastf1")
          library(reticulate)
          virtualenv_create("r-reticulate", Sys.which("python"))
          virtualenv_install("r-reticulate", python_packages)
          path_to_python <- virtualenv_python("r-reticulate")
          writeLines(sprintf("RETICULATE_PYTHON=%s", path_to_python),
                     Sys.getenv("GITHUB_ENV"))
@t-kalinowski
Copy link
Member

Thanks for reporting.

I beleive the development version of reticulate already has a fix for the latest r-devel. Do you still see the error if you install reticulate from main branch?

We'll have a new CRAN release in a few weeks time.

@pbulsink
Copy link
Author

pbulsink commented Mar 6, 2024

Thanks for that advice. I re-ran on GHA with reticulate from github and everything ran correctly.

For others who may experience the same issue and want to use reticulate from github instead of CRAN, I added the following lines before my setup-reticulate step (after r-lib/actions/setup-r-dependencies@v2):

      - name: Install remotes
        run: |
          Rscript -e "install.packages('remotes')"

      - name: Install dev reticulate from Github
        run: |
          Rscript -e "remotes::install_github('rstudio/reticulate')"

@eddelbuettel
Copy link
Contributor

eddelbuettel commented Sep 16, 2024

I am seeing the same error (in an Ubuntu 24.04 container) with version 1.39.0 which should have the fix.

Any idea? I installed packages python3-dev python3-pip python3-venv python-is-python3 from Ubuntu 24.04.

> library(reticulate)
> virtualenv_create()
Error in .make_numeric_version(x, strict, .standard_regexps()$valid_numeric_version) : 
  invalid non-character version specification 'x' (type: double)
>
>
> traceback()
8: stop(msg, domain = NA)
7: .make_numeric_version(x, strict, .standard_regexps()$valid_numeric_version)
6: numeric_version(x)
5: as.numeric_version(e2)
4: Ops.numeric_version(py_version, 3)
3: virtualenv_module(python)
2: module %||% virtualenv_module(python)
1: virtualenv_create()
>
> packageVersion("reticulate")
[1] ‘1.39.0’
> 

@t-kalinowski
Copy link
Member

Thanks for reporting. It looks like there are two stray py_version > 3 comparisons that I didn't update with the initial fix:

package <- if (py_version < 3) "python-pip" else "python3-pip"

However, those lines of code are only evaluated when we're already composing a nicer error message because pip or venv is missing. Since you've already installed python3-venv, something else is also going wrong, which we'll need to investigate.

@eddelbuettel
Copy link
Contributor

So I was trying to get a minimal environment going when batch package building. The displayed sudo apt install python3-venv is clearly not enough. Adding python3-pip python3-dev python-is-python3 appears to work once, but not when I restarted the container (huh?).

Could it be that we are running into subtle 'focal vs jammy' differences?

@eddelbuettel
Copy link
Contributor

Getting closer, thanks to your fine and focussed commit I was able to poke. I think the first test passes

root@78709e774099:/# Rscript -e 'reticulate:::python_has_module("/usr/bin/python3", "pip")'
[1] TRUE
root@78709e774099:/# 

but the second was not testing for venv present so my R 4.4.1 nagged over the comp with 3 instead of "3".

(This was after

apt update -qq; apt install r-cran-reticulate python3-pip python3-dev python3-venv python-is-python3

in a rocker/r2u:noble container.)

@t-kalinowski
Copy link
Member

t-kalinowski commented Sep 16, 2024

The only other thing I could think of is that this dpkg check failed because the output of dpkg changed subtly:

if (!any(grepl("\\bpython[0-9.]*-venv\\b", system("dpkg -l", intern = TRUE))))

However, I tried in docker containers derived from both rocker/r2u:noble and ubuntu:24.04 and was unable to reproduce the error. dpkg -l still gave the expected output, and reticulate::virtualenv_create() succeeded without issue after apt install -y python3-venv had run.

@eddelbuettel
Copy link
Contributor

Yes that works here too. (Same 22.04 container I still had open)

root@78709e774099:/# Rscript -e 'any(grepl("\\bpython[0-9.]*-venv\\b", system("dpkg -l", intern = TRUE)))'
[1] TRUE
root@78709e774099:/# 

@t-kalinowski
Copy link
Member

If you can share a Dockerfile where reticulate::virtualenv_create() errors, I'll be happy to take a look.

@eddelbuettel
Copy link
Contributor

Hm, that command works (after apt update -qq; apt install r-cran-reticulate python3-pip python3-dev python3-venv python-is-python3). So maybe my (much more feeble?) bug report is that the echo'ed line on sudo apt install python3-venv is to short?

@eddelbuettel
Copy link
Contributor

And the same command I ran a few comments and hours earlier, ie from inside R, now also works. I must have been missing python3-dev I guess?

@t-kalinowski
Copy link
Member

Thanks. I just pushed an update to improve the error message and mention python3-dev.

@eddelbuettel
Copy link
Contributor

I presume I could iterate and try to find the minimal set that let's us build the required venv.

(One thing, by the way, I was thinking but have been able to check with your code. Would having an env that auto-creates the default venv if missing be helpful?)

@t-kalinowski
Copy link
Member

Would having an env that auto-creates the default venv if missing be helpful?

Do you mean something like this?

reticulate:::.onLoad <- function(...) {
  ...
  if (!virtualenv_exists("r-reticulate") && 
      !is.null(virtualenv_starter())
    virtualenv_create()
}

@eddelbuettel
Copy link
Contributor

eddelbuettel commented Sep 16, 2024

Yep, pretty much. Because right now what happens is

  • package 'ABC' depends on reticulate
  • reticulate gets installed
  • reticalete dies on loading because no venv is there

Obviously, I can jump in and create it for the builds that need it (now that I know the missing ingredients) but it would be simpler if the needed step was executed auto'magic'ally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants