【发布时间】:2015-05-11 16:30:04
【问题描述】:
在 knitr 中运行 python 引擎时遇到问题。我可以导入一些模块,但不能导入其他模块。例如,我可以导入 numpy 但不能导入 pandas。
{r, engine='python'}
import pandas
我得到了错误。
Quitting from lines 50-51 (prepayment.Rmd)
Error in (knit_engines$get(options$engine))(options) :
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named pandas
Calls: <Anonymous> ... process_group.block -> call_block -> block_exec -> in_dir -> <Anonymous>
In addition: Warning message:
running command ''python' -c 'import pandas' 2>&1' had status 1
Execution halted
它必须与系统路径和我指向的位置有关。
我通常在 IPython 中使用
import sys
sys.path.append('/path/to/directory/')
添加路径。不知道是什么问题。
【问题讨论】:
-
您是否也尝试将
sys与 knitr 一起使用? -
所以我首先尝试将 sys 与 knitr 一起使用,但它不像在 IPython 中那样工作,所以我尝试了一些更简单的方法,比如导入 pandas,但没有成功。但我能够导入其他包,例如numpy...知道为什么吗?
-
您的包的来源是否在不同的地方?您可以使用 R 等效项,查看
Sys.getenv("path")。 -
你能发布你的包的分层描述吗?
标签: python r knitr sys reproducible-research