Bioconductor / basilisk

Clone of the Bioconductor repository for the basilisk package.
https://bioconductor.org/packages/devel/bioc/html/basilisk.html
GNU General Public License v3.0
27 stars 14 forks source link

Run python code in an environment specified by absolute path #5

Closed Jfortin1 closed 4 years ago

Jfortin1 commented 4 years ago

I'd like to run code in the conda python2 virtual environment already set up on my machine.

I'm able to do that if I start my R session from the folder containing that environment, that is the following works: results <- basiliskRun(basiliskStart("py2"), fun)) (where py2 is the name of my virtualenv) but results <- basiliskRun(basiliskStart("/Users/fortinj/miniconda3/envs//py2"), fun)) won't work when started from elsewhere.

It is easy to make it work?

LTLA commented 4 years ago

I'll assume you're operating outside of a package context, given the lack of pkgname=. I'll also assume you're operating on the latest basilisk, because I changed a few things (note that setupVirtualEnv has become setupBasiliskEnv, because Windows.)

If pkgname is not supplied, basiliskStart() (via useBasiliskEnv()) will look for virtual environments in the current working directory. You can force it to not do this by setting the BASILISK_NONPKG_DIR environment variable so that it looks somewhere else, e.g.,

Sys.setenv(BASILISK_NONPKG_DIR="/Users/fortinj/miniconda3/envs")
basiliskRun(envname="py2", fun) # no need to call `basiliskStart` directly in such a simple case.

Possibly this could be easier, but leaving pkgname=NULL was not considered to be a major use case. Indeed, I only added it to simplify testing.

Jfortin1 commented 4 years ago

Works, thanks!

LTLA commented 4 years ago

It should now be sufficient to pass in an absolute path to the environment.