Calling Python from R

Lazar

Phineas Packard
#1
So I am trying to call python from R so I can use beautiful soup. I have tried both
Code:
>system("python myfile.py")
and
Code:
>library(rPython)
>python.exec("import bs4 some more python script here")
The issue I am running into in both cases is I get back "No module named bs4"

I think the issue is that I have pip install bs4 on canopy python but r calls the stock python pre-installed on mac. Oddly running:

Code:
phparker$ python myfile.py
from bash works just fine so it seems to be an R specific issue.

Any help would be great or else I might have to figure out how to parse XML in R directly eeek
 

Dason

Ambassador to the humans
#2
If you use system can you call the version of python you want to use directly. So instead of
Code:
system("python myfile.py")
Code:
system("/path/to/version/you/want/python myfile.py")