I use Ubuntu 16.04. I'm trying to run a simple python script from R. The script is
import numpy as np
x=1
print(x)
and is written in a file named code.py. It works fine if I call it in bash via
python3.5 code.py
However, when I call it in R via
system("python3.5 code.py",intern=TRUE)
I get a message that says that numpy was not found. Any idea why there is this difference and how I can fix this?
Thanks!
UPDATE
If I run a file with
import sys
print(sys.path)
I get
[1] "['/home/user/Desktop', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5/dist-packages', '/usr/lib/python3/dist-packages']"
if I run the file from R, and
['/home/user/Desktop', '/home/user/anaconda3/lib/python35.zip', '/home/user/anaconda3/lib/python3.5', '/home/user/anaconda3/lib/python3.5/plat-linux', '/home/user/anaconda3/lib/python3.5/lib-dynload', '/home/user/anaconda3/lib/python3.5/site-packages', '/home/user/anaconda3/lib/python3.5/site-packages/Sphinx-1.4.1-py3.5.egg', '/home/user/anaconda3/lib/python3.5/site-packages/setuptools-23.0.0-py3.5.egg']
if I run the file from the command line.
import sys print(sys.path)