RStudio and python virtual environment - Python specified does not exist

I'm aiming to run python from RStudio. My setup is Windows RStudio Version 1.2.1335 and conda 4.7.12 from GitBash.

The RStudio support document (https://support.rstudio.com/hc/en-us/articles/360022909454-Best-Practices-for-Using-Python-with-RStudio-Connect) suggests creating a virtual environment in EVERY project.

Create virtual environment.

bash$ virtualenv .venv --python=python3.6

This creates a .venv directory in .

But then how to activate .venv? Running:

bash$ source activate .venv

Can't find .venv.

Running:

bash$ conda activate ./.venv
bash: [: too many arguments
bash: [: too many arguments
bash: [: too many arguments
bash: [: too many arguments
bash: [: too many arguments
bash: [: too many arguments
(c:\<project-dir>\.venv)

So the conda virtual env is running - not sure about the 'too many arguments' messages.

Then to RStudio.

Setting the in .Rprofile to ".venv/python". The .venv directory doesn't contain .venv/bin/python, instead the python.exe is at .venv/python.

Sys.setenv(RETICULATE_PYTHON = ".venv/python")

Restart R.

print("hello")

Error in py_discover_config(required_module, use_environment) :
Python specified in RETICULATE_PYTHON (.venv/python) does not exist

What am I doing wrong?

FYI, cross posting from SO post.

Solution:

Create virtual environment.

bash$ virtualenv .venv

This creates a .venv directory in .

Activate .venv.

bash$ source .venv/Scripts/activate

Then to RStudio.

Setting the in .Rprofile to ".venv/python". The .venv directory doesn't contain .venv/bin/python, instead the python.exe is at .venv/python.

library(reticulate)
Sys.setenv(RETICULATE_PYTHON = here::here(".venv/Scripts/python.exe"))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.