Skip to content

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

Closed

Description

@trafficonese

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

Activity

  1. salim-b commented on Sep 7, 2022

    @salim-b
    Contributor

    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/[email protected]")
    #> Using github PAT from envvar GITHUB_PAT
    #> Downloading GitHub repo rstudio/[email protected]
    #> 
    #> * 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

  2. lucius81 commented on Sep 14, 2022

    @lucius81

    This has worked for me:

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

    Thanks a lot!

  3. Dave-stack commented on Nov 7, 2022

    @Dave-stack

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

  4. cpsievert commented on Feb 13, 2023

    @cpsievert
    Collaborator

    Fixed by #2228

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions