findpython is an R package that finds acceptable Python binaries for
your program. Since there are often multiple python binaries installed
on any given system and they aren’t always added to the path this can
be a non-trivial task.
To install the latest version released to CRAN use:
install.packages("findpython")
To install the development version use:
remotes::install_github("trevorld/findpython")
It has no dependencies (other than R) but if you have the suggested
reticulate package installed it will also use it to try to find an
acceptable python binary. You’ll also need the suggested testthat
package to run the unit tests.
Usage
find_python_cmd() is the main function. It returns the path to a python
binary that meets certain requirements you specify. Below are some
examples.
If you need to find a Python 2 binary which is at least Python 2.4:
Although find_python_cmd() will create a basic default message if left
unspecified you can use the error_message argument to specify what
error message your program will output if it is unable to find an
acceptable binary:
library("findpython")
error_message <- paste('Was unable to find the Python 4 binary dependency.',
'See file INSTALL for more information.')
find_python_cmd(minimum_version = '4.0', error_message = error_message)
## Error in find_python_cmd(minimum_version = "4.0", error_message = error_message): Was unable to find the Python 4 binary dependency. See file INSTALL for more information.
There is also a wrapper for find_python_cmd() that instead of throwing
an error upon failing to find an appropriate Python command will return
FALSE and if it finds an appropriate command will return TRUE. If
successful it attaches the appropriate binary path as an attribute
python_cmd:
## Error in find_python_cmd(min = "4.0"): Couldn't find a sufficient Python binary. If you haven't installed the Python dependency yet please do so. If you have but it isn't on the system path (as is default on Windows) please add it to path or set options('python_cmd'='/path/to/binary') or set the PYTHON, PYTHON2, or PYTHON3 environmental variables. Python must be at least version 4.0
If you already have a python binary you want to check you can use
is_python_sufficient() to test whether it has sufficient features. It
has the same arguments minimum_version, maximum_version, and
required_modules as find_python_cmd():
findpython
findpythonis an R package that finds acceptable Python binaries for your program. Since there are often multiple python binaries installed on any given system and they aren’t always added to the path this can be a non-trivial task.To install the latest version released to CRAN use:
To install the development version use:
It has no dependencies (other than R) but if you have the suggested
reticulatepackage installed it will also use it to try to find an acceptable python binary. You’ll also need the suggestedtestthatpackage to run the unit tests.Usage
find_python_cmd()is the main function. It returns the path to a python binary that meets certain requirements you specify. Below are some examples.If you need to find a Python 2 binary which is at least Python 2.4:
If you need to find a version of Python at least Python 2.5 (but don't care if it is a Python 3 binary):
If you don’t care what version of Python you use but it needs to have access to an
argparsemodule as well as either thejsonORsimplejsonmodule:Although
find_python_cmd()will create a basic default message if left unspecified you can use theerror_messageargument to specify what error message your program will output if it is unable to find an acceptable binary:There is also a wrapper for
find_python_cmd()that instead of throwing an error upon failing to find an appropriate Python command will returnFALSEand if it finds an appropriate command will returnTRUE. If successful it attaches the appropriate binary path as an attributepython_cmd:The default error message will be something like:
If you already have a python binary you want to check you can use
is_python_sufficient()to test whether it has sufficient features. It has the same argumentsminimum_version,maximum_version, andrequired_modulesasfind_python_cmd():License
This package is available under the MIT license.