1

因此,我将有各种需要获取 python 脚本的项目。

据我了解,网状 pkg 可以帮助我们在 RStudio 中使用 virtualenvs。

virtualenv_list() 将返回virutalenvs 的可用名称。

但由于我已经有一个包含所有虚拟环境的文件夹,我想使用它而不是默认文件夹:

来自:https ://rstudio.github.io/reticulate/reference/virtualenv-tools.html

虚拟环境默认位于 ~/.virtualenvs。您可以通过定义 WORKON_HOME 环境变量来更改此行为。

如何定义 WORK_HOME 变量?

文件夹的路径,我有不同的 virtualenvs:

/home/gonzales/Escritorio/virtual_envs

我的虚拟环境之一的路径:

/home/gonzales/Escritorio/virtual_envs/stickers-gallito-env/

我找到了这段代码来找到要处理的 RProfile:

> candidates <- c( Sys.getenv("R_PROFILE"),
+                  file.path(Sys.getenv("R_HOME"), "etc", "Rprofile.site"),
+                  Sys.getenv("R_PROFILE_USER"),
+                  file.path(getwd(), ".Rprofile") )
> 
> Filter(file.exists, candidates)
[1] "/usr/lib/R/etc/Rprofile.site" "/home/gonzales/.Rprofile"  

如果我编辑 Rprofile.R

file.edit("/home/gonzales/.Rprofile")

然后保存更改:

WORKON_HOME = "/home/gonzales/Escritorio/virtual_envs/"

然后尝试:

library(reticulate)

virtualenv_list()

我去拿:

character(0)

为什么它不起作用?

> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.1 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale:
 [1] LC_CTYPE=es_PE.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=es_PE.UTF-8        LC_COLLATE=es_PE.UTF-8    
 [5] LC_MONETARY=es_PE.UTF-8    LC_MESSAGES=es_PE.UTF-8   
 [7] LC_PAPER=es_PE.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=es_PE.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

loaded via a namespace (and not attached):
[1] compiler_3.4.4 tools_3.4.4    yaml_2.2.0 
4

1 回答 1

0

有关在 ubuntu 中设置环境变量的不同方法,请参阅https://askubuntu.com/questions/730/how-do-i-set-environment-variables

将以下内容添加到 /etc/environment:WORKON_HOME="/home/gonzales/Escritorio/virtual_envs"然后注销并重新登录。

然后运行virtualenv_list()应该列出您在该位置拥有的虚拟环境。

于 2019-05-18T21:18:11.763 回答