I have a python project that uses two R packages. I have to use these packages because they don't exist for Python as of today. While my project works great, one obstacle is that users have to install these two packages using R (or R studio) in their local systems. I was wondering if it is possible to add these package names in the python projects requirements.txt file so that they get installed with other python packages. Any leads on this are helpful... just trying to make it easy for the users of my project.
Asked
Active
Viewed 351 times
0
-
1Unless Python wrappers exist or these libraries are otherwise available on PyPI, no, this isn't possible via `requirements.txt`. But there are other options for wrapping stuff up. I think Conda can do this, or you could package it as an OS-specific installer / DEB / RPM / DMG. – ChrisGPT was on strike Dec 22 '20 at 04:06
-
Are the two packages available via version control (git, mercurial, subversion, bazar)? You might be able to at least download the package then but never tried it. Otherwise I agree with @Chris that the answer is "no". – Allan Wind Dec 22 '20 at 04:08
-
1Presumably you'd need an R runtime to use the libraries, even if you can somehow pull them in via version control. A Python wrapper would have to package that up, too. – ChrisGPT was on strike Dec 22 '20 at 04:15
-
Thanks folks! I kinda sensed it might not be possible but thought I should ask. One option I might try is import the base R in python using importr('base) and then inside python try something like if package not installed then install.packages('package-name') --> this is assuming that install.packages is actually a part of base R – RforResearch Dec 22 '20 at 16:29
1 Answers
1
As essentially answered in the comments, Python and R have completely different packaging systems. It is not possible to add R packages to requirements.txt
because is it used to store Python packages.
However, you could have setup code for your Python package install R packages when your Python code is installed or at runtime. In that case the R packages are installed using R's own packaging system, and nothing prevents you from storing them in a flat file (for example called requirements_r.txt
).
A word of caution though. Installing a Python package that has the side effect of changing the directory of available R packages might be frowned upon by some.

lgautier
- 11,363
- 29
- 42