Skip to content
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

Config/reticulate in package DESCRIPTION file does not install Python dependencies #883

Closed
mcanigueral opened this issue Nov 11, 2020 · 3 comments
Milestone

Comments

@mcanigueral
Copy link

I'm using my own Python functions wrapped by my R package functions, so I have the Python Pandas dependency in my R Package.
I would like to see all my Python dependencies installed in the project's active Python environment when I install my package from GitHub. Thus, I have been following this article of reticulate.
I have introduced the following to the DESCRIPTION file, whith pip = FALSE since I want to use condaenv:

Config/reticulate:
  list(
    packages = list(
        list(package = "pandas", pip = FALSE)
    )
  )

And I have introduced the following to an R script package_utils.R in package's R/ folder:

pyenv <- new.env()
.onLoad <- function(libname, pkgname) {
    reticulate::configure_environment(pkgname, force = TRUE)
    reticulate::source_python(system.file("python/utils.py", package = pkgname), envir = pyenv)
}

The python script with my Python functions is located in package's inst/python/utils.py folder, and all functions are loaded in a global environment pyenv in order to be accessible from all other R functions.

Then, when I make the CRAN check or install the package i get the following error:

/bin/bash: /home/mcanigueral/Desktop/R packages/evflex/renv/python/condaenvs/renv-python/lib/libtinfo.so.6: no version information available (required by /bin/bash)
Updating evflex documentation
Loading evflex
Error in py_run_file_impl(file, local, convert) : 
  ModuleNotFoundError: No module named 'pandas'

Then, the Config/reticulate in DESCRIPTION is not installing the dependencies automatically. What do I need to configure a part from these files above?

Thanks!

@kevinushey kevinushey added this to the 1.19 milestone Feb 4, 2021
@kevinushey
Copy link
Collaborator

Then, when I make the CRAN check or install the package i get the following error:

The biggest problem here is that normally, R packages shouldn't be downloading and installing software onto the CRAN build machines when running tests. I also think it is unlikely to me that you would want to spend time debugging test failures that might only occur on CRAN's machines.

All that said, I have a test package here:

https://github.com/kevinushey/usespandas

and it seems to work as expected:

remotes::install_github("kevinushey/usespandas")

library(reticulate)
library(usespandas)

conda_create("usespandas-test")
use_condaenv("usespandas-test", required = TRUE)

py_config()
py_module_available("pandas")

I see:

> library(reticulate)
> library(usespandas)
> conda_create("usespandas-test")
Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... done

## Package Plan ##

  environment location: /Users/kevinushey/Library/r-miniconda/envs/usespandas-test

  added / updated specs:
    - python


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    certifi-2020.12.5          |   py39h6e9494a_1         143 KB  conda-forge
    python-3.9.1               |h2502468_5_cpython        12.6 MB  conda-forge
    python_abi-3.9             |           1_cp39           4 KB  conda-forge
    setuptools-49.6.0          |   py39h6e9494a_3         950 KB  conda-forge
    tzdata-2021a               |       he74cb21_0         121 KB  conda-forge
    ------------------------------------------------------------
                                           Total:        13.8 MB

The following NEW packages will be INSTALLED:

  ca-certificates    conda-forge/osx-64::ca-certificates-2020.12.5-h033912b_0
  certifi            conda-forge/osx-64::certifi-2020.12.5-py39h6e9494a_1
  libcxx             conda-forge/osx-64::libcxx-11.0.1-habf9029_0
  libffi             conda-forge/osx-64::libffi-3.3-h046ec9c_2
  ncurses            conda-forge/osx-64::ncurses-6.2-h2e338ed_4
  openssl            conda-forge/osx-64::openssl-1.1.1i-h35c211d_0
  pip                conda-forge/noarch::pip-21.0.1-pyhd8ed1ab_0
  python             conda-forge/osx-64::python-3.9.1-h2502468_5_cpython
  python_abi         conda-forge/osx-64::python_abi-3.9-1_cp39
  readline           conda-forge/osx-64::readline-8.0-h0678c8f_2
  setuptools         conda-forge/osx-64::setuptools-49.6.0-py39h6e9494a_3
  sqlite             conda-forge/osx-64::sqlite-3.34.0-h17101e1_0
  tk                 conda-forge/osx-64::tk-8.6.10-h0419947_1
  tzdata             conda-forge/noarch::tzdata-2021a-he74cb21_0
  wheel              conda-forge/noarch::wheel-0.36.2-pyhd3deb0d_0
  xz                 conda-forge/osx-64::xz-5.2.5-haf1e3a3_1
  zlib               conda-forge/osx-64::zlib-1.2.11-h7795811_1010



Downloading and Extracting Packages
setuptools-49.6.0    | 950 KB    | ########## | 100% 
tzdata-2021a         | 121 KB    | ########## | 100% 
python_abi-3.9       | 4 KB      | ########## | 100% 
certifi-2020.12.5    | 143 KB    | ########## | 100% 
python-3.9.1         | 12.6 MB   | ########## | 100% 
Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done
#
# To activate this environment, use
#
#     $ conda activate usespandas-test
#
# To deactivate an active environment, use
#
#     $ conda deactivate

[1] "/Users/kevinushey/Library/r-miniconda/envs/usespandas-test/bin/python"
> use_condaenv("usespandas-test", required = TRUE)
> py_config()

Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... done

## Package Plan ##

  environment location: /Users/kevinushey/Library/r-miniconda/envs/usespandas-test

  added / updated specs:
    - pandas


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    libblas-3.9.0              |       8_openblas          11 KB  conda-forge
    libcblas-3.9.0             |       8_openblas          11 KB  conda-forge
    libgfortran-5.0.0          |9_3_0_h6c81a4c_17          19 KB  conda-forge
    libgfortran5-9.3.0         |      h6c81a4c_17         1.7 MB  conda-forge
    liblapack-3.9.0            |       8_openblas          11 KB  conda-forge
    llvm-openmp-11.0.1         |       h7c73e74_0         268 KB  conda-forge
    numpy-1.20.0               |   py39h3c955ea_0         5.4 MB  conda-forge
    pandas-1.2.1               |   py39h089d6f7_0        10.8 MB  conda-forge
    pytz-2021.1                |     pyhd8ed1ab_0         239 KB  conda-forge
    ------------------------------------------------------------
                                           Total:        18.5 MB

The following NEW packages will be INSTALLED:

  libblas            conda-forge/osx-64::libblas-3.9.0-8_openblas
  libcblas           conda-forge/osx-64::libcblas-3.9.0-8_openblas
  libgfortran        conda-forge/osx-64::libgfortran-5.0.0-9_3_0_h6c81a4c_17
  libgfortran5       conda-forge/osx-64::libgfortran5-9.3.0-h6c81a4c_17
  liblapack          conda-forge/osx-64::liblapack-3.9.0-8_openblas
  libopenblas        conda-forge/osx-64::libopenblas-0.3.12-openmp_h54245bb_1
  llvm-openmp        conda-forge/osx-64::llvm-openmp-11.0.1-h7c73e74_0
  numpy              conda-forge/osx-64::numpy-1.20.0-py39h3c955ea_0
  pandas             conda-forge/osx-64::pandas-1.2.1-py39h089d6f7_0
  python-dateutil    conda-forge/noarch::python-dateutil-2.8.1-py_0
  pytz               conda-forge/noarch::pytz-2021.1-pyhd8ed1ab_0
  six                conda-forge/noarch::six-1.15.0-pyh9f0ad1d_0



Downloading and Extracting Packages
libcblas-3.9.0       | 11 KB     | ########## | 100% 
numpy-1.20.0         | 5.4 MB    | ########## | 100% 
libgfortran-5.0.0    | 19 KB     | ########## | 100% 
liblapack-3.9.0      | 11 KB     | ########## | 100% 
libblas-3.9.0        | 11 KB     | ########## | 100% 
llvm-openmp-11.0.1   | 268 KB    | ########## | 100% 
libgfortran5-9.3.0   | 1.7 MB    | ########## | 100% 
pytz-2021.1          | 239 KB    | ########## | 100% 
pandas-1.2.1         | 10.8 MB   | ########## | 100% 
Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done
Done!
python:         /Users/kevinushey/Library/r-miniconda/envs/usespandas-test/bin/python
libpython:      /Users/kevinushey/Library/r-miniconda/envs/usespandas-test/lib/libpython3.9.dylib
pythonhome:     /Users/kevinushey/Library/r-miniconda/envs/usespandas-test:/Users/kevinushey/Library/r-miniconda/envs/usespandas-test
version:        3.9.1 | packaged by conda-forge | (default, Jan 26 2021, 01:32:59)  [Clang 11.0.1 ]
numpy:           [NOT FOUND]

NOTE: Python version was forced by use_python function
> py_module_available("pandas")
[1] TRUE

@mcanigueral
Copy link
Author

Thanks for your answer!
I see now that the installation of Python dependencies specified in Config/reticulate is done when running py_config(). I missed this part.
I'm closing this. Thanks again.

@kevinushey
Copy link
Collaborator

In particular, it's done as soon as Python is initialized -- so packages can be loaded, users can configure the version of Python to be used, and then once a version of Python is selected the requisite Python modules can be installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants