在 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/')
添加路径。我不知道问题是什么。