# Python chunk fails to run in windows desktop version with error: This application failed to start because it could not find or load the Qt platform plugin "windows" in "". #4182

Closed
opened this issue Jan 19, 2019 · 26 comments · Fixed by #5051

### System details

RStudio Edition : Desktop
RStudio Version : 1.2.1242
OS Version      : Windows 10 Pro
R Version       : 3.5.2


### Steps to reproduce the problem

Run this simple python chunk

---
title: "R Notebook"
output: html_notebook
---

{python}
import pandas



### Describe the problem in detail

When I try to run a python chunk y get this error and my R session crashes.

I have python installed through Anaconda 3 distribution, this used to work normally some daily builds ago, but I can't specify which one.

Contributor

### kevinushey commented Jan 22, 2019

 This should work with the development builds of reticulate. What is the output of packageVersion("reticulate") on your machine? Does: devtools::install_github("rstudio/reticulate")  make a difference?
Author

### andresrcs commented Jan 22, 2019

 My reticulate version was 1.10, I have installed the development version and now works normally, thanks.

### ronblum commented Feb 8, 2019

 On MacOS, the current version of reticulate ((1.10) causes a new RStudio instance to start to open, but remains bouncing and doing nothing. It requires quitting the app to keep going. The development build works, though. I'm leaving this marked as an open issue, to retest once a new production version reticulate is published.
added the label Feb 8, 2019

### icalandra commented Jun 27, 2019

 I still have the same problem, as described by @andresrcs Windows 10 Pro, version 1803, OS build 17134.829 Anaconda 3 with Python 3.7.3 R 3.6.0 RStudio 1.2.1335 reticulate 1.12.0.9003 The problem seems to be only with Python plotting commands, other Python calculations seem fine. I searched quite a lot online but I cannot understand any of the answers. Thanks for any help!
added this to the v1.2-patch milestone Jun 27, 2019
Contributor

### kevinushey commented Jun 27, 2019

 @icalandra I suspect your issue is different. @andresrcs's issue involved RStudio crashing even when pandas was imported; yours is explicitly around plotting. A reproducible example would be helpful.

### icalandra commented Jun 28, 2019 • edited by kevinushey

 Thanks for the answer. Indeed, my problem seems to be different, although the error is the same, which is why I thought the problem was similar. I can plot Python commands from a Python script or directly writing in the console. But I cannot knit it: --- title: "Untitled" author: "xx" date: "28/06/2019" output: html_document --- {python} import numpy as np from matplotlib import pyplot as plt xs = np.linspace(0,10) ys = 3*xs +1  {python} fig, ax = plt.subplots() ax.plot(xs,ys) plt.show()   The first chunk runs fine and exports to HTML correctly (if I remove the second chunk), but the second crashes and I get the error shown in the original thread. Any idea? Thanks, Ivan

### icalandra commented Jun 28, 2019 • edited

 Oh, I didn't expect the markdown part would be interpreted; how can I avoid it? But I guess you got it.
Contributor

### kevinushey commented Jun 28, 2019

 You can use backtick code 'fences' to avoid that sort of rendering, e.g.  # This is some Markdown {r} print("Hello!")    I've edited your post to do that (hope that's okay).

### icalandra commented Jul 1, 2019

 @kevinushey thanks for the tip! The real problem still remains though...
referenced this issue Jul 2, 2019

### icalandra commented Jul 9, 2019

 Any pointer anyone? Thanks again!

### ronblum commented Jul 9, 2019

 @icalandra The fix for both issues—covered by #5051—is slated for the upcoming update to 1.2.

### icalandra commented Jul 10, 2019

 Great, thanks!

### ronblum commented Jul 10, 2019

 @icalandra You're welcome! When the next preview is available, this should be working. If you're still running into the issue then, please let us know!
closed this Jul 10, 2019
reopened this Jul 10, 2019

### icalandra commented Jul 11, 2019

 I will!
added the label Jul 30, 2019

### ronblum commented Jul 30, 2019

 @icalandra Have you had a chance to try out the latest preview and see if it works?

### icalandra commented Jul 31, 2019

 Euu... how do I install it? I currently have reticulate 1.13.0.9000 installed and I still have the issue

### ronblum commented Jul 31, 2019

 @icalandra I'm sorry—I meant the RStudio preview at https://www.rstudio.com/products/rstudio/download/preview/. (Note that Preview builds are intended for testing purposes only.)

### ronblum commented Jul 31, 2019

 The original issue is confirmed, using the current production version of reticulate, 1.13. I'm leaving this in "verifying" state, for the moment, because of the second issue.

### icalandra commented Aug 1, 2019

 I can confirm that the problem persists with the latest RStudio preview (1.2.1565).

### ronblum commented Aug 1, 2019 • edited

 I get a different error, even though the plot is rendered. In the R Markdown pane, the log ends with Fatal Python error: PyEval_RestoreThread: NULL tstate The error modal below appears, as well. There's no problem if the file only contains the first chunk when knitted, or if the chunks are running individually. So even though we're getting different results, it seems like your original issue is still there, so I'm reopening.
reopened this Aug 1, 2019
removed the label Aug 13, 2019
assigned kevinushey and unassigned ronblum Aug 13, 2019
changed the title Python chunch fails to run in windows desktop version with error: This application failed to start because it could not find or load the Qt platform plugin "windows" in "". Python chunk fails to run in windows desktop version with error: This application failed to start because it could not find or load the Qt platform plugin "windows" in "". Aug 13, 2019

### linderd commented Aug 14, 2019 • edited

 I found a walkaround to solve the problem with the help from this stackoverflow The solution was to add these two lines to the R code: py_run_string("import os as os") py_run_string("os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = 'C:/Path_to_your_anaconda/anaconda3/Library/plugins/platforms'") Hope I could help you EDIT: Works fine but I still get a crash when I terminate my execution.
self-assigned this Aug 16, 2019

### icalandra commented Aug 19, 2019

 The code chuncks do run, but I get an error at the end and no HTML file as a result. Did I do something wrong? Here is my code: --- title: "Untitled" author: "xx" date: "28/06/2019" output: html_document --- {r} library(reticulate) py_run_string("import os as os") py_run_string("os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = 'C:/Users/.../Anaconda3/Library/plugins/platforms'")  {python} import numpy as np from matplotlib import pyplot as plt xs = np.linspace(0,10) ys = 3*xs +1  {python} fig, ax = plt.subplots() ax.plot(xs,ys) plt.show()   And here is the error: output file: test2.knit.md "C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS test2.utf8.md --to html4 --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash+smart --output test2.html --email-obfuscation none --self-contained --standalone --section-divs --template "C:\Users\calandra\Documents\R\win-library\3.6\rmarkdown\rmd\h\default.html" --no-highlight --variable highlightjs=1 --variable "theme:bootstrap" --include-in-header "C:\Users\calandra\AppData\Local\Temp\Rtmp2bgJSj\rmarkdown-str29544bf85fbb.html" --mathjax --variable "mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" Access violation in generated code when executing data at 0x7a48e89 Attempting to reconstruct a stack trace... Frame Code address 0x57adaf0 0x7a48e89 0x57adaf8 0x1d40101 C:\PROGRA~1\RStudio\bin\pandoc\pandoc.exe+0x1940101 0x57adb00 0xd70 0x57adb08 0x22e 0x57adb10 0x58d4510 0x57adb18 0x5 0x57adb20 0x73020d0000 0x57adb28 0x22e 0x57adb30 0xc68 0x57adb38 0x7aa5c09 0x57adb40 0x7a08491 0x57adb48 0x20 0x57adb50 0x61 0x57adb58 0x7af6fa1 0x57adb60 0x7af80e8 0x57adb68 0x7af81a8 0x57adb70 0x7af8180 0x57adb78 0x7aed6d1 0x57adb80 0x1 0x57adb88 0x57 0x57adb90 0x7a794d0 0x57adb98 0x4f 0x57adba0 0x7a2df08 0x57adba8 0x7ad8481 0x57adbb0 0x4b61721 C:\PROGRA~1\RStudio\bin\pandoc\pandoc.exe+0x4761721 0x57adbb8 0x49f2be2 C:\PROGRA~1\RStudio\bin\pandoc\pandoc.exe+0x45f2be2 0x57adbc0 0x4b616f1 C:\PROGRA~1\RStudio\bin\pandoc\pandoc.exe+0x47616f1 0x57adbc8 0x423fbc8 C:\PROGRA~1\RStudio\bin\pandoc\pandoc.exe+0x3e3fbc8 0x57adbd0 0x7ac0540 0x57adbd8 0x7ac0509 0x57adbe0 0x49f0aba C:\PROGRA~1\RStudio\bin\pandoc\pandoc.exe+0x45f0aba 0x57adbe8 0x49f0aba C:\PROGRA~1\RStudio\bin\pandoc\pandoc.exe+0x45f0aba 0x57adbf0 0x423fba8 C:\PROGRA~1\RStudio\bin\pandoc\pandoc.exe+0x3e3fba8 0x57adbf8 0x49f0aba C:\PROGRA~1\RStudio\bin\pandoc\pandoc.exe+0x45f0aba 0x57adc00 0x7ac0680 ... (maximum recursion depth reached.) Error: pandoc document conversion failed with error 11 Execution halted
Contributor

### kevinushey commented Aug 26, 2019

 @icalandra are you using the preview release of RStudio?

### icalandra commented Aug 27, 2019

 I just tried again with the latest preview release of RStudio (1.2.1572) and @linderd solution works, without errors: --- title: "Untitled" author: "xx" date: "28/06/2019" output: html_document --- {r} library(reticulate) py_run_string("import os as os") py_run_string("os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = 'C:/Users/calandra/Anaconda3/Library/plugins/platforms'")  {python} import numpy as np from matplotlib import pyplot as plt xs = np.linspace(0,10) ys = 3*xs +1  {python} fig, ax = plt.subplots() ax.plot(xs,ys) plt.show()   So it seems to all work correctly now, thank you all for your help!
referenced this issue Aug 27, 2019
Contributor

### kevinushey commented Aug 27, 2019 • edited

 As far as I can tell, all of the associated issues in this thread have been fixed (with the workaround for QP_QPA_PLATFORM_PLUGIN_PATH). I've filed an issue on the reticulate side to see if we can handle that better: rstudio/reticulate#586 Since this issue has become rather long and unwieldy, if you find you're still running into a problem please open a new issue (with a reproducible example). Thanks!
closed this Aug 27, 2019
added the label Aug 27, 2019

### icalandra commented Aug 28, 2019

 Thanks!