Open koverholt opened 5 years ago
Can you reproduce this error without reticulate? IIUC the error is occurring while attempting to initialize matplotlib.
I cannot reproduce the error without reticulate.
If I run the Python script on the same Linux machine with the same Python version I point to above, it runs without any errors, and I can even add plt.savefig("python-error.png")
and successfully get a rendered plot.
This error seems similar:
https://gist.github.com/grzegorz-siekaniec/238b32bebd42d16eb676#file-scikit-learn_issue_4664
I wonder if there are other errors in the stack trace that are being lost? (it looks like the output was truncated; not sure if that was done by reticulate or not)
Agreed, it looks similar, and I saw some other issues about the stack trace being lost.
The puzzling part for me is that it runs fine in Python but fails in reticulate when trying to change to any matplotlib backend.
I'm getting a "SyntaxError: invalid or missing encoding declaration" when attempting to render an Rmarkdown document that uses
matplotlib
and theAgg
backend (since I'm using a remote Linux machine).The document renders fine on my local machine on macOS.
The error appears in RStudio on Linux whether I try to render with knit or execute the cell in an Rmarkdown notebook. And it works if I run it with the Python environment I am pointing to that contains numpy and matplotlib. If I remove the matplotlib code, then
reticulate
works with Python as expected.OS: Ubuntu 14.04 R version: 3.4.4
Input Rmarkdown file:
processing file: python-error.Rmd |................ | 25% ordinary text without R code
|................................ | 50% label: setup (with options) List of 1 $ include: logi FALSE
|................................................. | 75% ordinary text without R code
|.................................................................| 100% label: unnamed-chunk-1 (with options) List of 2 $ include: logi TRUE $ engine : chr "python"
Quitting from lines 12-24 (python-error.Rmd) Error in py_run_string_impl(code, local, convert) : SyntaxError: invalid or missing encoding declaration for '/opt/python/bin/python3'
Detailed traceback: File "", line 1, in
File "/opt/python/lib/python3.4/site-packages/matplotlib/init.py", line 1407, in use
stacklevel=2)
File "/usr/lib/python3.4/warnings.py", line 18, in showwarning
file.write(formatwarning(message, category, filename, lineno, line))
File "/usr/lib/python3.4/warnings.py", line 26, in formatwarning
line = linecache.getline(filename, lineno) if line is None else line
File "/usr/lib/python3.4/linecache.py", line 15, in getline
lines = getlines(filename, module_globals)
File "/usr/lib/python3.4/linecache.py", line 41, in getlines
return updatecache(filename, module_globals)
File "/usr/lib/python3.4/linecache.py", line 126, in updatecache
with tokenize.open(fullname) as fp:
File "/usr/lib/python3.4/tokenize.py", line 439, in open
encoding, lines = detect_encoding(buffer.readline)
File "/usr/lib/
Calls: ... force -> py_run_string -> py_run_string_impl -> .Call
Execution halted