【问题标题】:Calling python from R's system(): pandas not found从 R 的 system() 调用 python:找不到熊猫
【发布时间】:2021-12-04 16:49:16
【问题描述】:

我继承了一个(糟糕的)项目,其中 R 通过 R 的 system() 系统地调用 Python 脚本。

我知道这是一个非常糟糕的做法,但老实说,我没有时间补救它。

问题是,我不得不迁移到一台新机器,没有关于如何配置机器的文档,现在,如果我打电话给python3.8 "myscript.py" "arg1" "arg2",它会完美地导入 pandas。 当我(来自 R)system(paste("python3.8"," ","myscript.py"," ",arg1," ",arg2),,wait=TRUE) 时,脚本在 import pandas as pd 处失败。

我什至尝试将python3.8 "myscript.py" "arg1" "arg2" 封装成myscriptcaller.sh 并调用(来自R)system(paste("python3.8"," ","myscriptcaller.sh"," ",arg1," ",arg2),,wait=TRUE),结果相同。

我感到困惑和绝望。有什么想法吗?

【问题讨论】:

  • 两个调用之间的 sys.path 是否不同
  • 不,不一样
  • 其实,很奇怪...我擦除了机器(Ubuntu 20),创建了一个新机器(Ubuntu 16),降级到 R 3.4.4,这种行为消失了......
  • 更奇怪的是:在全新的 Ubuntu 20.04 中,我无法重现这种奇怪的行为......

标签: python r pandas system


【解决方案1】:

您可以尝试验证您是否在 R 和系统中使用相同的 python "which python",以防它们运行不同

system(paste("full/path/python"," ", "myscript.py"," ",arg1," ",arg2),,wait=TRUE)

【讨论】:

  • 我确实指定了 /usr/bin/python3.8。值得注意的是,我在那台机器上没有任何其他 python 安装
猜你喜欢
  • 2018-02-21
  • 1970-01-01
  • 1970-01-01
  • 2021-10-14
  • 1970-01-01
  • 1970-01-01
  • 2016-02-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多