因此,我将有一系列需要源代码python脚本的项目。
据我所知,reticulate pkg可以帮助我们在RStudio中使用virtualenv。
virtualenv_list()将返回病毒环境的可用名称。
但由于我已经有了一个包含所有虚拟环境的文件夹,我想用它来代替默认文件夹:
发件人:https://rstudio.github.io/reticulate/reference/virtualenv-tools.html
默认情况下,虚拟环境位于~/.virtualenvs。您可以通过定义WORKON_HOME环境变量来更改此行为。
如何定义WORK_HOME变量
文件夹的路径,在那里我有不同的虚拟机:
/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
请参阅https://askubuntu.com/questions/730/how-do-i-set-environment-variables了解在ubuntu中设置环境变量的不同方法。
将以下内容添加到/etc/environment:WORKON_HOME="/home/gonzales/Escritorio/virtual_envs"
,然后注销并重新登录。
然后运行virtualenv_list()
应该列出您在该位置的虚拟环境。