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

save_image not working. 'sys' is not defined in py_run_string_impl #2179

Closed
trafficonese opened this issue Sep 5, 2022 · 4 comments
Closed

Comments

@trafficonese
Copy link

Trying the kaleido example, I get this error and no picture.

library(plotly)
p <- plot_ly(x = 1:10)
save_image(p, "./pic.png")

Error in py_run_string_impl(code, local, convert) :
NameError: name 'sys' is not defined

@salim-b
Copy link
Contributor

salim-b commented Sep 7, 2022

This seems to be some kind of regression with latest reticulate 1.26. It was also reported on Stack Overflow.


With reticulate 1.25 it works as usual:

remotes::install_github("rstudio/reticulate@v1.25")
#> Using github PAT from envvar GITHUB_PAT
#> Downloading GitHub repo rstudio/reticulate@v1.25
#> 
#> * checking for file ‘/tmp/RtmpIYtuHK/remotes13a887430565e/rstudio-reticulate-38978a1/DESCRIPTION’ ... OK
#> * preparing ‘reticulate’:
#> * checking DESCRIPTION meta-information ... OK
#> * cleaning src
#> * checking for LF line-endings in source and make files and shell scripts
#> * checking for empty or unneeded directories
#> * building ‘reticulate_1.25.tar.gz’
#> Installing package into '/home/salim/.by_pkg_mngr/r'
#> (as 'lib' is unspecified)

library(plotly)
#> Loading required package: ggplot2
#> 
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#> 
#>     last_plot
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following object is masked from 'package:graphics':
#> 
#>     layout
p <- plot_ly(x = 1:10)
save_image(p, "./pic.png")
#> No trace type specified:
#>   Based on info supplied, a 'histogram' trace seems appropriate.
#>   Read more about this trace type -> https://plotly.com/r/reference/#histogram

Created on 2022-09-07 with reprex v2.0.2


A workaround for reticulate 1.26 is to call import sys in Python before executing save_img():

install.packages("reticulate")
#> Installing package into '/home/salim/.by_pkg_mngr/r'
#> (as 'lib' is unspecified)

library(plotly)
#> Loading required package: ggplot2
#> 
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#> 
#>     last_plot
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following object is masked from 'package:graphics':
#> 
#>     layout
p <- plot_ly(x = 1:10)
reticulate::py_run_string("import sys")
save_image(p, "./pic.png")
#> No trace type specified:
#>   Based on info supplied, a 'histogram' trace seems appropriate.
#>   Read more about this trace type -> https://plotly.com/r/reference/#histogram

Created on 2022-09-07 with reprex v2.0.2

@lucius81
Copy link

This has worked for me:

library(reticulate)
reticulate::py_run_string("import sys")

Thanks a lot!

@Dave-stack
Copy link

#Error in py_run_string_impl(code, local, convert) :
#NameError: name 'sys' is not defined
reticulate::py_run_string("import sys")
finally, NO COMPLAIN

@cpsievert
Copy link
Collaborator

Fixed by #2228

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

No branches or pull requests

5 participants