-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
conda env support #1
Comments
It does work with conda. We actually scan for conda environments here: https://github.com/rstudio/reticulate/blob/master/R/python_config.R#L66-L76 So by default if the first package you import is named "tensorflow" then we'll look in e.g. ~/anaconda/envs/tensorflow automatically. Outside of that you can use either the RETICULATE_PYTHON environment variable to point to the python binary in your conda env or just make sure the env bin directory is first on the path as described here: https://github.com/rstudio/reticulate#locating-python Open to any and all suggests for how we can make binding to conda environments more natural and straightforward. |
I should have known this was already something you would consider! My only bit of advice may be that conda itself comes with a way of listing what environments it knows about:
So it may be valuable to tie into that plumbing. Aside from adding an explicit call, something like |
Okay, thanks. I'll look into that. |
@earino I've implemented a family of use functions that simplify configuration of conda envs, virtual envs, etc. Documentation is here: https://github.com/rstudio/reticulate/#locating-python |
@jjallaire cool am gonna test, will let you know any results on my family of environments. |
@jjallaire I got the following error:
I stepped through with the debugger, and even though "conda" is set with the correct path, conda_locations isn't set:
Note that my conda is in /usr/local/anaconda and your path.expands is not looking there?
This seems like where the bug is. |
Found the issue and just pushed a fix. Try again and let me know if it is now working. Thanks! |
I have good news and I have bad news. :) The good news is that
(note that to get this to work, you need to install spacy and then execute This is the environment.yml i used to define this conda environment:
On a wholly unrelated note, if you're taking requests for C tools to wrap in R, may I suggest Dan Bloomberg's incredible leptonica library? (http://www.leptonica.com/) by far the best image processing library I ever used for morphological image processing. |
Seems like your argument to |
Yes, I noticed that as well ( Let's close this issue and the file a new one if the problem isn't just the type of |
@terrytangyuan thanks for your observation. i assure you I try to read error messages :) I don't believe this was a simple case, as this code was taken from this example https://nicschrading.com/project/Intro-to-NLP-with-spaCy/ I am attaching a session of me running that code, including enabling the
@jjallaire if you want, i will open up another issue. |
@terrytangyuan I did some further looking (thanks for the encouragement!) I can see that spaCy calls parseC with a Doc object here: and when I look I see that this is the Doc class, and how to instantiate it: https://github.com/explosion/spaCy/blob/master/spacy/tokens/doc.pyx#L60
This implied to me that I should be able to explicitly construct a Doc object (though sadly it's not needed in the native python implementation.) I was able to get past the error message with the following change:
This no longer blows up with an error message. Unfortunately it just returns a NULL :) I will keep hunting this down. Cheers and thanks for this module! |
In the example code it looks like they are using unicode string literals. In Python 2 we marshall R strings as 8-bit strings whereas in Python 3 we marshall them as Unicode strings. I wonder if the API explicitly requires Unicode strings and if in the case that you are running Python 2 that would be the problem. We could overcome this by providing an explicit |
I managed to reproducible case under Python 2.7 and found two things:
Here's the code that behaves as expected working around both issues:
I'll have to think about what the best way to handle callable objects in R is. |
Okay, I added an library(reticulate)
use_condaenv("spacy_environment")
spacy <- import("spacy.en")
parser <- as.function(spacy$English())
multiSentence = "There is an art, it says, or rather, a knack to flying.
The knack lies in learning how to throw yourself at the ground and miss.
In the beginning the Universe was created. This has made a lot of people
very angry and been widely regarded as a bad move."
parsedData <- parser(multiSentence) |
@jjallaire seems reasonable. From an API standpoint, my mind was moving towards dplyr's Something like: library(reticulate)
use_condaenv("spacy_environment")
spacy <- import("spacy.en")
parser <- spacy$English()
multiSentence = "There is an art, it says, or rather, a knack to flying.
The knack lies in learning how to throw yourself at the ground and miss.
In the beginning the Universe was created. This has made a lot of people
very angry and been widely regarded as a bad move."
parsedData <- do(parser, multiSentence) With the idea that maybe someday you could have these callable objects in dplyr pipelines? I definitely hadn't thought it out all the way through. Regardless, implemented code beats ideas any day. |
The |
I had an issue when I was trying to build a wrapper around custom_fn in TF.Learn. The function being returned by the R function turns out to be an environment instead of a function. Would that be related to this? |
It could be that it's returning a callable object rather than a function. Try BTW we now represent Python objects as environments rather than raw externalptrs (this is so that we can delay load modules until after the |
Will try it out. I might need to setup Travis soon to test tensorflow and reticulate changes regularly. |
We've added a So the code would now read: parser <- spacy$English()
multiSentence <- "...."
parsedData <- parser$call(multiSentence) |
Nice!
…On Fri, Feb 10, 2017 at 3:39 PM, JJ Allaire ***@***.***> wrote:
We've added a $call() method for slightly nicer syntax (d16d51b
<d16d51b>
).
So the code would now read:
parser <- spacy$English()multiSentence <- "...."parsedData <- parser$call(multiSentence)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AEEnSr5mEnUaAXT_s6Mq-Do_ln7AlOEpks5rbNkUgaJpZM4L54e3>
.
|
An update, as of the latest development version of reticulate you can now call Python callable objects with the standard R function call syntax (you don't need the special
While in the above example the |
👍 |
This package is brilliant. One of the ways that we've seen users leverage python in DS is by using the conda package manager, specifically conda environments. Does this package have the ability to say something like "enable conda environment foo" and have your R code leverage that particular build/stack?
The text was updated successfully, but these errors were encountered: