Do not automatically activate slendr Python virtual environment upon loading the package #118
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
From NEWS:
Minor breaking change! Python environments of slendr are no longer automatically activated upon calling
library(slendr)
! Using the coalescent msprime back end and slendr's tree-sequence functions now requires making an explicit call to a new functioninit_env()
afterlibrary(slendr)
is executed.Motivation for the change: A small proportion of users have been experiencing issues with broken conda environments and various other issues with Python virtual environments in general. It's hard to guess how frequent this has been, but experience from workshops and courses suggests perhaps 1 in 20 of users experiencing Python issues which hindered their ability to use slendr . (Fun fact: the first user-submitted GitHub issue upon releasing the first version of the slendr R package was... a Python virtual environment issue).
Explanation: Activating Python environments automatically upon calling
library(slendr)
has been a popular feature because it hid away most of the complexities of the R-Python interface that powers slendr's tree-sequence functionality. This has been a convenient feature particularly for users who have no experience with Python at all.Unfortunately, in cases where a Python virtual environments with tskit/msprime/pyslim on a user's system ended up corrupted (or if anything else at the Python level got broken), the automatic Python environment activation performed by the
library(slendr)
call failed and slendr was not even loaded. Sadly, this completely pulled the rug from under slendr and there was nothing that could be done about it from its perspective (the issue happened at a low-level layer of embedded-Python which slendr has no control over).Solving these issues was not difficult for experienced users, but many slendr users have no experience with Python at all, they have never used conda, they don't understand the concept of "Python virtual environments" or how the R-Python interface works. And nor should they! After all, slendr is an R package.
Splitting the Python virtual environment activation step into its own
init_env()
function means thatlibrary(slendr)
now always succeeds (regardless of potential underlying Python issues on a user's sytem), making it much easier to diagnose and fix Python problems from R once the package is loaded.So, to recap:
library(slendr)
no longer activates slendr's isolated Python virtual environment. In order to simulate tree sequences and analyse them using its interface to tskit, it is necessary to callinit_env()
first (just once, after callinglibrary(slendr)
). This function performs the same Python-activation steps thatlibrary(slendr)
used to call automagically in earlier slendr versions. Nothing else in the R-Python interface changes.