You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用reticulate执行install_python()时遇setwd错误求助

问题描述

按照TensorFlow RStudio安装流程操作时,执行install_python()命令遇到权限相关报错,无法继续:

> library(reticulate)
> path_to_python <- install_python()
Error in setwd(root) : cannot change working directory

环境信息

> sessionInfo()
R version 4.3.0 (2023-04-21 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621)

Matrix products: default


locale:
[1] LC_COLLATE=English_United States.utf8 
[2] LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                           
[5] LC_TIME=English_United States.utf8    

time zone: America/Chicago
tzcode source: internal

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

other attached packages:
[1] reticulate_1.28

loaded via a namespace (and not attached):
[1] compiler_4.3.0 Matrix_1.5-4   tools_4.3.0    rappdirs_0.3.3
[5] Rcpp_1.0.10    grid_4.3.0     jsonlite_1.8.4 png_0.1-8     
[9] lattice_0.21-8

4月23日更新:该问题已提交至对应项目Issue。

解决建议
  • 以管理员身份运行R/RStudio:Windows系统中右键点击R或RStudio图标,选择「以管理员身份运行」,重新执行install_python()。权限不足是触发该报错的常见原因。
  • 指定自定义安装路径:手动指定一个你拥有读写权限的目录安装Python,示例代码如下:
    library(reticulate)
    # 替换为你有权限的目标目录,版本号可按需调整
    path_to_python <- install_python(python_version = "3.10", destdir = "C:/Users/你的用户名/Documents/Python")
    
  • 切换到有权限的工作目录:先执行getwd()查看当前工作目录,确认是否有读写权限。若无权限,先通过setwd("你的权限目录路径")切换,再执行安装命令。
  • 更新reticulate包:执行update.packages("reticulate")将包更新至最新版本,可能修复了权限相关的已知问题。

内容的提问来源于stack exchange,提问作者J.Z.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 20:27:24