-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Allow to choose installation environment #146
Comments
No wonder everyone uses virtual and conda envs in Python if you run into troubles with incompatibilities so quickly 😄 (bashing over). I actually considered that in #134. Problem: Potentially complicated because executables from conda environments are not on the path by default (I think). So to find an executable, one had to look through all conda envs
I think the first option is clearly preferred. What do you think? |
I would go with the first one. At the moment I'm setting up a Docker image with miniconda3, precommit, keras, and mlflow. When all of them are installed in their separate conda environments (respectively r-reticulate, r-tensorflow, r-mlflow-1.7.0) I experience no problems while mixing up their functionality. I was able to train a keras model with mlflow-registered parameters and utilize precommit when committing changes. The only additional thing that has to be done is to call However I would expect that all of those tools could be installed inside a single conda environment, similarly to e.g. |
Ok, great, then I'll implement that. Note that {precommit} does not depend on any python module directly, it only depends on the executable. You can consider it a coincidence that pre-commit was written in Python in the first place, which in turn means that it will work independently of the activated conda environment (and Well, I have experienced such problems before and there are also some very narrow version requirements for some python libraries that make them incompatible easily. |
Surprisingly, on Windows, the executable cannot really be run with I think this is a problem because I don't know how to For the time being, you could also consider alternative installation methods such as pip. |
Turns out that it is possible to install pre-commit and keras into the same conda environment from R interface. The following code works: precommit::install_precommit()
keras::install_keras("conda", conda_python_version = NULL,
tensorflow = "2.2.0rc2") By default the keras package forces Python 3.6 version, hardcoded in the This results in a library with Python 3.8.2 version (since the first installation step considered only pre-commit). However, in this case inside the conda environment most of the modules are installed from pip. The steps can be reversed keras::install_keras()
precommit::install_precommit() And then it just works, but the Python version is 3.6.10 due to the mentioned hardcoded parameter. pre-commit doesn't care about the Python version in this case. Now most of the modules are installed from conda-forge. When running name: r-reticulate
channels:
- defaults
- conda-forge
- pypi
dependencies:
- python=3.8.2
- pre-commit
- keras there will be conflicts found. This is due to fact, that even if the pypi channel is available on Anaconda Cloud, there are no packages inside it. To use pip packages with conda the following structure has to be set up name: r-reticulate
channels:
- defaults
- conda-forge
dependencies:
- python=3.8.2
- pre-commit
- pip
- pip:
- keras
- tensorflow Strangely tensorflow has to be explicitly listed. This is the closest setup to the very first one in this comment, with some minor changes. Basically when creating any kind of virtual environment we usually list the desired packages at the same time and the environment sorts itself out. This is not the case for R. It's true, that we can I wonder if there could be a common R package solution for installing Python envs. Not overall one like the reticulate package, but something that would automatically install R packages as well. |
Interesting investigation. So if I got you right, installing the python packages from outside of R works fine but when you install into the conda env via R, the trouble starts, in particular when packages like R {keras} or {tensorflow} have fixed python version requirements? As from my experience, it's generally better to avoid installing packages into a conda env with So I think RStudio works on a solution you might be interested. Also, I find it quite frustrating that command line executables don't work in general if the conda env is not activated as described above. This basically makes conda a bad solution for hosting such executables. |
Yes, and even if someone overcomes this with proper parameters set I guess it still could be dangerous, since R package interface could be incompatible with particular version of the Python module. As for the solution you have mentioned - this looks promising.
Maybe it will make more sense if I install miniconda through reticulate instead of manually, borrowing from Docker image mentioned in the first comment. Getting rid of |
@krzyslom I wonder if you can't convince the people in rstudio/keras3#1014 to install into the |
|
@lorenzwalthert from this reticulate article I understand, that the approach the community is aiming at and will possibly become a standard, is to add the Actually tensorflow is already doing this but keras is not. Should precommit, mlflow, keras, etc. have this field set up with library(precommit)
library(mlflow)
library(keras)
<pkg>::<fnc> and the conda environment should be automatically set up. Or users could just set them all up in This way all packages could just use the one default |
Thanks for the explanation. The difference to most python packages is that {precommit} only needs the executable and no Python function and I not sure the former is supported in this approach. The automated installation described in the article you link also would require anyone to use miniconda to use {precommit}, but some consider this a heavy dependency so we also support other installation methods. I found a workaround to install into r-precommit in #147 I believe so I won't use |
I guess that the workaround and configured DESCRIPTION file could complement each other # can be conda, virtualenv, pip installation
precommit::install_precommit()
precommit::use_precommit()
# Installs to r-precommit B) DESCRIPTION # R miniconda installation
library(precommit)
use_precommit()
# if not already installed - install miniconda through reticulate package? -> Y
# installs to `r-reticulate` and figures out python packages automatically Since precommit does not depend on any Python modules, its installation should never clash with already existent I can try this when the workaround PR gets merged. |
Yeah I think we could also use approach B) later. But I think I spend so much time already on that that I'd like to move on for now. Also, maybe it's better to wait and see how the
Yeah but in my understanding it's a likely scenario anyways, so since pre-commit does not have a lot of dependencies, I think it's a good option to install into its own environment. |
As mentioned in #113 . Recently I've tried to run
keras::install_keras()
inside the Docker image with already installed precommit. Looks like both keras and tensorflow are now installed by default tor-reticulate
.This results in the following error:
The text was updated successfully, but these errors were encountered: