【发布时间】:2021-07-31 06:26:35
【问题描述】:
我使用来自 RStudio 的 Python 和 reticulate 包。是否可以像在普通 Python 中一样创建自定义模块并导入它们?这是一个 MWE:
我的自定义模块存储在一个名为 test_class.py 的文件中,并定义了 Test 类:
class Test:
def __init__(self, name):
self.name = name
我的主文件 main.py 与 test_class.py 位于同一目录中并包含
from test_class import Test
x = Test("Bobby")
print(x.name)
如果我使用 reticulate 在 RStudio 中运行主文件,则会失败并显示:ModuleNotFoundError: No module named 'test_class'。如果我使用 python (python main.py) 在终端中运行它,它会完美运行。如何在 RStudio 中获得这种行为?
【问题讨论】:
标签: python class module rstudio reticulate