python - R网状在第二个python文件中导入模块不起作用
问题描述
我在通过调用的 python 脚本中加载模块时遇到问题reticulate
。
我的文件结构基本上是这样的:
Rscript.R
library(reticulate)
py_run_file("python1.py")
python1.py
print("test1")
import python2 as p2
p2.run_test(123)
python2.py
def run_test(x):
print("inside p2-run_test()")
print(x)
现在,如果我正在运行Rscript.R
,它可以正常工作,但是像这样更改python2.py
(添加一个新功能):
python2.py
def run_test(x):
print("inside p2-run_test()")
print(x)
def run_test2(x):
print("inside p2-run_test2()")
print(x)
像这样python1.py
(调用所述函数):
python1.py
print("test1")
import python2 as p2
p2.run_test2(123)
我收到以下错误:
test1
Error in py_run_file_impl(file, local, convert) :
AttributeError: 'module' object has no attribute 'run_test2'
有人可以在这里帮助我如何解决这个问题吗?
解决方案
正如 nicola 在评论中所说,这可以通过重新加载导入的模块来解决:
然后,您想在编辑后重新加载 python 模块。请参见此处:如何将模块“重新导入”到 python,然后在导入后更改代码
那为我修好了。
推荐阅读
- javascript - 表格提交前重新格式化日期
- java - 我想制作一个 Android API 以在主屏幕上保持屏幕唤醒
- mysql - 如何在 sparql 查询中遍历图?
- angular - 如何在 Redux 中处理 Odata?
- android - 在 Mac 中:处理命令时发生未知的服务器端错误原始错误:找不到 adb
- javascript - javascript,错误未从 api 显示
- python-3.x - 在 DataFrame 上完成 groupby 时,如何获取单个组内的差异值
- git - git rebase 和/或 git merge create 是否标记了冲突?
- r - 缺少的类别显示在底部
- list - 得到“致命错误:索引超出范围”:在 swiftui 的列表项中显示索引