rstudio / reticulate

R Interface to Python
https://rstudio.github.io/reticulate
Apache License 2.0
1.68k stars 328 forks source link

Error message when using pydotplus via reticulate #1002

Open sebastien-foulle opened 3 years ago

sebastien-foulle commented 3 years ago

Hello,

a minimal exemple :

from sklearn import datasets, tree
import pydotplus

# Load data
iris = datasets.load_iris()
X = iris.data
y = iris.target

# Create decision tree and train model
clf = tree.DecisionTreeClassifier(random_state = 0)
clf.fit(X, y)

# Create and export DOT data
dot_data = tree.export_graphviz(clf,
                                feature_names = iris.feature_names,
                                class_names = iris.target_names,
                                out_file = None,
                                filled = True,
                                rounded = True)

graph = pydotplus.graph_from_dot_data(dot_data)

# "OSError: [WinError 6] Descripteur non valide"  (in English "OSError: [WinError 6] The handle is invalid")
graph.write_png('tree.png')

The code works in pycharm, spyder and jupyterlab but not in Rstudio. My sessionInfo() :

R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252    LC_MONETARY=French_France.1252 LC_NUMERIC=C
[5] LC_TIME=French_France.1252
system code page: 65001

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
 [1] compiler_4.0.3    Matrix_1.3-2    tools_4.0.3     yaml_2.2.1      Rcpp_1.0.6     reticulate_1.20-9000 grid_4.0.3
 [8] jsonlite_1.7.2     png_0.1-7       lattice_0.20-41
akhan619 commented 2 years ago

Similar issue except it happens when using the plot(model) function in Keras.