我在 knitr 中运行 python 引擎时遇到问题。我可以导入一些模块,但不能导入其他模块。例如,我可以导入 numpy 但不能导入 pandas。
{r, engine='python'}
进口 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/')
添加路径。我不知道是什么问题。
最佳答案
使用:
{python engine.path="C:/anaconda/python.exe"}
import pandas
将 C:/anaconda/python.exe
更改为您的 python
路径。
关于python - knitr - 导入 python 模块时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30172948/