Reticulate: Choosing a specific python version in conda create

Created on 16 May 2020  路  7Comments  路  Source: rstudio/reticulate

Hello,

I am developing a new r package to access the eikon python api.
I want this python module to run in its own conda environment.
I am however unable to influence the python version of the conda environment using reticulate::conda_create while > https://docs.conda.io/projects/conda/en/latest/user-guide/getting-started.html#managing-python states that this is possible within conda itself.
However in reticulate::conda_create() I could not find an option to set a specific python version. Also setting packages = "python36" and other similar variations failed as well
````
PackagesNotFoundError: The following packages are not available from current channels:

  • python36
    ````

I am having issues with running eikon on python 3.8.2. Therefore I would like to switch back to 3.6.10 on which it runs perfectly.
I am currently thinking for package development purposes it would be preferable to have a separate conda environment within the package. So using r-reticulate as environment in the package is not advisable as a potential workaround. Please advise.

thanks and regards,

Laurens

reticulate::conda_create(envname = "r-eikon", packages = c("python") )

when I then check

reticulate::use_condaenv(condaenv = "r-eikon", conda = "auto", required = TRUE)) # set virtual environment right
reticulate::py_install(packages = c("numpy", "eikon") , envname = "r-eikon",  method = method, conda = conda)t
reticulate::py_config()

gives

python:         C:/Users/XXXX/AppData/Local/r-miniconda/envs/r-eikon/python.exe
libpython:      C:/Users/XXXX/AppData/Local/r-miniconda/envs/r-eikon/python38.dll
pythonhome:     C:/Users/XXXX/AppData/Local/r-miniconda/envs/r-eikon
version:        3.8.2 | packaged by conda-forge | (default, Apr 24 2020, 07:34:03) [MSC v.1916 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:/Users/XXXX/AppData/Local/r-miniconda/envs/r-eikon/Lib/site-packages/numpy
numpy_version:  1.18.4
eikon:          C:\Users\XXXX~1\AppData\Local\R-MINI~1\envs\r-eikon\lib\site-packages\eikon\__init__.p

NOTE: Python version was forced by use_python function

When I then check the conda environments available with reticulate::conda_list() gives:

          name                                                                             python
1  r-miniconda                     C:\\Users\\XXXX\\AppData\\Local\\r-miniconda\\python.exe
2        eikon        C:\\Users\\XXXX\\AppData\\Local\\r-miniconda\\envs\\eikon\\python.exe
3      r-eikon      C:\\Users\\XXXX\\AppData\\Local\\r-miniconda\\envs\\r-eikon\\python.exe
4 r-reticulate C:\\Users\\XXXX\\AppData\\Local\\r-miniconda\\envs\\r-reticulate\\python.exe

when I then switch back to the r-reticulate environment:
```
python: C:/Users/XXX/AppData/Local/r-miniconda/envs/r-reticulate/python.exe
libpython: C:/Users/XXXXAppData/Local/r-miniconda/envs/r-reticulate/python36.dll
pythonhome: C:/Users/XXXX/AppData/Local/r-miniconda/envs/r-reticulate
version: 3.6.10 (default, Mar 5 2020, 10:17:47) [MSC v.1900 64 bit (AMD64)]
Architecture: 64bit
numpy: C:/Users/XXXX/AppData/Local/r-miniconda/envs/r-reticulate/Lib/site-packages/numpy
numpy_version: 1.18.1

NOTE: Python version was forced by use_python function
````

Most helpful comment

I've now added the python_version argument to conda_create(), to make this more explicit. In the development version of reticulate (+ upcoming 1.19 release), you should be able to execute:

reticulate::conda_create("my-environment", python_version = "3.6")

to request an installation of (for example) Python 3.6.

All 7 comments

Hello,
i'm trying to use the library "youtubecaption" which uses reticulate. The creator of youtubecaption tried to help me and then realized that I should ask for the help of the creators of reticulate. i have the simplest code:

url = "https://www.youtube.com/watch?v=RQeeVWA6jgA"
c <- get_caption(url)

and I'm getting:

Error in value[[3L]](cond) : 
  Need to install Anaconda from https://www.anaconda.com/download/.
Error in system2(conda, args = c("info", "--json"), stdout = TRUE, stderr = FALSE) : 
  'CreateProcess' failed to run 'D:\Anaconda\condabin\conda.bat info --json'

I am however unable to influence the python version of the conda environment using reticulate::conda_create while > https://docs.conda.io/projects/conda/en/latest/user-guide/getting-started.html#managing-python states that this is possible within conda itself.

True, conda_create() should have this option, python version control is an important issue

I am having the same problem. Any update on this issue?

I'm surprised this issue got no attention

reticulate::conda_create(
   envname = "test",
   packages = "python=3.7"
)

You can use python=<version> to request a specific Python version when creating the Conda environment.

You can use python=<version> to request a specific Python version when creating the Conda environment.

Thank you @kevinushey , great to know!
It would be very helpful to have it documented at the function.

I've now added the python_version argument to conda_create(), to make this more explicit. In the development version of reticulate (+ upcoming 1.19 release), you should be able to execute:

reticulate::conda_create("my-environment", python_version = "3.6")

to request an installation of (for example) Python 3.6.

Was this page helpful?
0 / 5 - 0 ratings