0

I'm having trouble doing even the most basic things with the reticulate library in R Studio. My code looks as follows:

library(reticulate)
use_python("C:\\Users\\User2017\\AppData\\Local\\Programs\\Python\\Python36\\python.exe")
 req <- import("requests")

With the last line I get an error

parse error: trailing garbage
          2017\\Documents\\.condarc" } Using Anaconda Cloud api site h
                     (right here) ------^

How can I get this working? Using requests is just for example, every other package fails. The python I'm pointing the reticulate package to is the system wide python that has various packages already installed.

My specs from running sessionInfo() :

R version 3.5.3 (2019-03-11)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252    LC_MONETARY=English_Australia.1252
[4] LC_NUMERIC=C                       LC_TIME=English_Australia.1252    

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

other attached packages:
[1] reticulate_1.11.1

loaded via a namespace (and not attached):
[1] compiler_3.5.3  Matrix_1.2-15   tools_3.5.3     yaml_2.2.0      Rcpp_1.0.1      grid_3.5.3      jsonlite_1.6   
[8] lattice_0.20-38
smci
  • 32,567
  • 20
  • 113
  • 146
West
  • 2,350
  • 5
  • 31
  • 67
  • You need to tell us on what version of R, what version of R Studio and What OS you are working. `sessionInfo()` would be good – M-- Mar 21 '19 at 20:50
  • 1
    First, you can use raw-string to avoid the double-backslashes: `r"C:\Users\User2017\..."`. Second, seems like you're picking up some Anaconda configuration string, path, compile option, whatever. Does this only happen with `import("requests")`, or other package? Can you post the full trace of the error? – smci Mar 22 '19 at 00:47
  • @smci The error I posted is all that comes up. The python I'm pointing has the requests library installed as well as all the others that I cant import – West Mar 22 '19 at 07:31
  • **Does this only happen with import("requests"), or with other packages?** Please try other packages like I asked then tell us. Are you sure Anaconda installed `requests` package properly? Please try reinstalling `requests` then confirm. You're expected to make some effort to do your own troubleshooting, not just post *"It's broken"* and stop there. I didn't downvote you but I can understand why other people would. Each of us encounters similar issues all the time. – smci Mar 22 '19 at 07:56
  • @smci Yes none of the installed packages work thats what I meant on previous comment. I'm pointing reticulate to the system wide python installation which has various packages installed, not the one from Anaconda, though I have anaconda installed too. The request library and all the others work well when I'm just working in python on a different IDE. To be fair I really think my question was clear enough all I did was import a library and shouldn't be this hard. I understand if someone needed more info to diagnose my issue but its not like I didnt put effort trying to fix this myself – West Mar 22 '19 at 08:54
  • `py_install("requests")` also fails with the same error as on the post. using `requests` is just for example, every other package fails – West Mar 22 '19 at 08:59
  • Seems like an issue with Anaconda. I googled the error message and found exact hits on [Error trailing garbage](https://community.rstudio.com/t/error-trailing-garbage/24100) and in [comment by Ritesh Verma on the tutorial](https://eswomen.com/id/image-recognition-classification-with-keras-in-r-tensorflow-for-machine-intelligence-by-google-iExh0qj2Ouo.html). If this only happens under Anaconda, try manually installing a clean install of R and reticulate without using Anaconda, then use that to troubleshoot/workaround the error. If you find the cause please report it to Anaconda and RStudio. – smci Mar 22 '19 at 09:15
  • 1
    (For context, Anaconda quality went down the toilet in 2017 and it's considered near-broken and is losing users. If it's causing you trouble, workaround it with a non-Anaconda install and report the issue to both RStudio and Anaconda. Anaconda's configuration is way too complex, underdocumented and bug-prone.) – smci Mar 22 '19 at 09:17
  • I suspect some config file setting, installation or environment-variable setting for Anaconda cloud API (not even sure you need that) is messed up, or undefined, or wrongly escaped under Windows. Googling that error message also turns up [Anaconda Command Reference](https://docs.anaconda.com/anaconda-cloud/commandreference/). But it might be faster in the short term to workaround with a non-Anaconda install. Your choice. Let us know what you tried. – smci Mar 22 '19 at 09:23
  • @smci Thanks for the advice I'll give that a try and let you know how it went. This happened before I installed Anaconda so when I seen the error referring to Anaconda I decided to install it just to see what happens. I have installed Anaconda in the past but I had uninstalled it, though I realised there was some left over files in certain folders. Anaconda wasn't in Path on windows so I'm not sure why it was being picked up. I'll uninstall and delete everything related to Anaconda and R Studio, start afresh and see how it goes. – West Mar 22 '19 at 22:35
  • @smci I didn't notice before but I've realised I still had some Anaconda version installed. Uninstalling it and just using python makes everything work as expected. Thanks a lot! – West Apr 08 '19 at 07:23

1 Answers1

2

The same problem on my side:

pandas <- import("pandas") 
Error: parse error: trailing garbage
      Documents\\.condarc" } Using Anaconda Cloud api site h
                 (right here) ------^

I have followed the suggestions of smci: after removing Anaconda from my computer and re-linking to another python installation, the problem has disappeared:

use_python("~/Python36/python")
os <- import("os")

Hope that helps!

Addition: Python 2.7.11, Anaconda2 4.0.0 64-bit

Artyom
  • 209
  • 2
  • 5
  • Ok. If you get it running under Anaconda, please come back and let us know. Also useful to record the versions of things (Anaconda, conda, reticulate etc.). If you or anyone ever find the root-cause please report a github issue to Anaconda. – smci Apr 09 '19 at 07:49
  • I have added the version of Anaconda & python - reticulate version 1.11.1. Haven't investigated it further. – Artyom Apr 09 '19 at 22:37
  • Each conda executable also has its own version number, it helps if you also show `conda -V` – smci Apr 10 '19 at 03:06
  • It was removed together with Anaconda, can't find the version anymore - there are just some traces on my computer like cache/*.json from conda & condamanagerlog. If you point me where to look, I can check there. – Artyom Apr 13 '19 at 16:42
  • Artyom: no worries, in future please include version numbers. As to Anaconda, everyone please actively report [issues on their github](https://github.com/ContinuumIO/anaconda-issues/issues), hope they can fix their quality issues... – smci Apr 14 '19 at 10:37