MyNixOS website logo
Description

Functions to Find an Acceptable Python Binary.

Package designed to find an acceptable python binary.

findpython

CRAN Status Badge

R-CMD-check

Coverage Status

RStudio CRAN mirror downloads

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:

> library("findpython")
> find_python_cmd(minimum_version = '2.4', maximum_version = '2.7')
[1] "/usr/bin/python"

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):

> find_python_cmd(minimum_version = '2.5')
[1] "/usr/bin/python"

If you don't care what version of Python you use but it needs to have access to an argparse module as well as either the json OR simplejson module:

> find_python_cmd(required_modules = c('argparse', 'json | simplejson'))
[1] "/usr/bin/python"

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:

> 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:

> did_find_python <- can_find_python_cmd()
> python_cmd <- attr(did_find_python, "python_cmd")
> cat(did_find_python, python_cmd, "\n")
TRUE /usr/bin/python

The default error message will be something like:

> find_python_cmd(min='4.0')
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:

> is_python_sufficient(path_to_binary, minimum_version = '2.6', required_modules = 'scipy')
[1] FALSE

License

This package is available under the MIT license.

Metadata

Version

1.0.8

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows