detect virtual environments created with venv#370
Merged
Conversation
9506ad0 to
2fa659a
Compare
Collaborator
Author
|
Note that this PR does indeed ensure Python sets reticulate::use_virtualenv("~/scratch/venv", required = TRUE)
reticulate::py_config()
#> python: /Users/kevin/scratch/venv/bin/python
#> libpython: /usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin/libpython3.7.dylib
#> pythonhome: /usr/local/opt/python/Frameworks/Python.framework/Versions/3.7:/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7
#> version: 3.7.0 (default, Sep 18 2018, 18:47:22) [Clang 9.1.0 (clang-902.0.39.2)]
#> numpy: [NOT FOUND]
#>
#> NOTE: Python version was forced by use_python function
sys <- reticulate::import("sys")
sys$prefix
#> [1] "/Users/kevin/scratch/venv"
sys$exec_prefix
#> [1] "/Users/kevin/scratch/venv"Created on 2018-10-23 by the reprex package (v0.2.1) So at least this PR passes the smoke tests. Can you think of anything else I should double-check just to be sure? |
Member
|
Does the |
Collaborator
Author
|
We set the Lines 107 to 109 in 2fa659a |
Member
|
Will merge now, let’s be sure to add a NEWS item |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR is the first step in support for Python virtual environments created by
venv.Note that these virtual environments are almost identical to those created with
virtualenv. The only difference is that theactivate_this.pyscript is missing. My understanding is thatactivate_this.pyis a hack that tries to allow an existing Python session to bind to an existing virtual environment; whereas the preferred route is to instead run e.g.which works as expected for virtual environments created by both
virtualenvandvenv.Something we should discuss then is whether we need any other code changes to support virtual environments that don't contain this script. I see we use it at e.g.
reticulate/src/python.cpp
Lines 1433 to 1458 in 93c9ee9
It's worth noting that
bin/activateeffectively does two things:VIRTUAL_ENVenvironment variable; its path points to the virtual environment,Assuming that embedded Python sessions also respect the
VIRTUAL_ENVenvironment variable, we should validate that setting that before initializing Python is enough to ensure that the newly-launched Python session uses the virtual environment as requested.