I use a self installed python distribution in my home directory. Everything woks well. However, R behaves quite strange,system('python -V')
returns the version of python installed on /usr/bin/python
. If I execuete Sys.which('python')
, the system python path is returned. How can I set R to execute python
in the home directory instead of system wide python. I do not want to add absolute path to the code, since the code is running on different machine.
Asked
Active
Viewed 229 times
0

Kattern
- 2,949
- 5
- 20
- 28
-
Why just not call `system('/correct_path/python -V')`? – romants Nov 24 '14 at 03:00
-
1Have you added your self-installed Python's directory to the PATH? – Marius Nov 24 '14 at 03:10
-
@Marius Yes, the python is executed correctly from Terminal. – Kattern Nov 24 '14 at 04:10
-
@romantsegelskyi The code is used on Mac and Windows at the same time, I do not like to maintain two version of the code in the program. – Kattern Nov 24 '14 at 04:11
-
It's a long shot, but maybe try `system2` instead of `system` – romants Nov 24 '14 at 04:20
-
@romantsegelskyi already tried, same result. – Kattern Nov 24 '14 at 07:23
-
Do you have this problem on both OSes? Does the correct path appear in `Sys.getenv('PATH')`? – jbaums Nov 24 '14 at 07:24
-
@jbaums actually yes. Slightly different, I have only one python under Windows, but has some odd behaviors too. [Check this out](https://stackoverflow.com/questions/27097787/anaconda-mkl-not-licensed-properly-when-called-from-r). Maybe they are caused by the same reason. – Kattern Nov 24 '14 at 07:27
-
1Sorry - edited my comment a bit late. Does the correct Python path exist in `Sys.getenv('PATH')`? It seems that on OSX, environment variables in `.profile` [aren't inherited by GUI apps](https://support.rstudio.com/hc/communities/public/questions/200629578-system-call-from-RStudio-does-not-find-path-same-command-from-commandline-R-works-fine-). Are you using R terminal, or e.g. RStudio (and is the behaviour consistent across the two?)? – jbaums Nov 24 '14 at 07:34
-
@jbaums Yes, I am using RStudio on OSX. You are right, the command works in R terminal, but not RStudio. It seems I have to start RStudio from commandline to avoid this problem. – Kattern Nov 24 '14 at 07:41
-
In that case, maybe [this](http://stackoverflow.com/a/7502061/489704) will help. – jbaums Nov 24 '14 at 07:43
-
also try: `utils::install.packages` instead of just `install.packages` RStudio has some weird overwrites that can be avoided this way.... – phonixor Nov 24 '14 at 10:15