[Rd] Robust, platform independent method to check for python

Gabor Grothendieck ggrothendieck at gmail.com
Sat Jun 27 22:04:56 CEST 2009


I think that most python installations won't have a
registry key set.  I have python 2.6 and 2.5 on my
machine but searching the registry found no
occurrence of the string python.   At least the path method
has the advantage that if its not set then the user
only has to modify the path whereas if its not
in the registry the user would have to reinstall python
and to make it worse they would have to use
specific distributions that install a key. Furthermore
they would be stuck if they can't access the registry
on their machine.

Also if its on the path then you don't actually need
to find its location as system("python ...") or
shell("python ...") should find it itself.  For
example, if you have python on  your path try
   system("python --help")
from the R command line.

Depending on how much work you are willing to do
you could check the path, the registry and common
locations such as c:\Python26, c:\Python,
c:\Program Files\Python, etc. and provide a
pythonpath= argument to your function so if even
all those don't work the user can supply the path.

Here is how two other packages handle this

1. read.xls in the gdata package uses perl and the way
it works is to assume that perl is on the path and if
not there is an argument to the function so that the
user can specify its location.

2. The rSymPy package uses python via jython (python
running on java) and actually includes the entire jython
in the package itself to eliminate external dependencies.
If your python code is pure python it should run on jython
in which case you could simply add rSymPy as a dependency
and then use jython from it.  That would work cross platform
and the only dependency eternal to R would be java itself
but that is nearly universal -- much more prevalent than pytyhon.

One thing that would be convenient would be if R had a
package for each of the common scripting languages
such as perl, python and ruby that included the respective
language processor.  This would be help even if
there were no sophisticated interface (as in the case with
tcl) simply so that other packages that provide interfaces to
code in those languages could know where the
scripting language processor is located.

On Sat, Jun 27, 2009 at 1:51 PM, Steve
Weston<steve at revolution-computing.com> wrote:
> You can also try to find Python on Windows machines by
> reading the registry using the R readRegistry function (added
> sometime around R 2.7.0, I think).  You can't count on the
> information being there, but it often is, depending on how
> Python was installed.
>
> Using the registry seems to work better than using PATH,
> since the standard Python installer doesn't update PATH,
> although the ActiveState Python installer does.  But both
> approaches can fail, depending on the options that were
> specified when Python was installed.
>
> Good luck,
>
> - Steve
>
>
> On Sat, Jun 27, 2009 at 12:01 PM, Gabor
> Grothendieck<ggrothendieck at gmail.com> wrote:
>> If you can assume its on your path then try this:
>>
>> pth <- sapply(strsplit(Sys.getenv("PATH"), ";"), function(x)
>> file.path(x, "python.exe", fsep = "\\"))
>> pth[file.exists(pth)][1]
>>
>> On Sat, Jun 27, 2009 at 11:44 AM, Carlos J. Gil
>> Bellosta<cgb at datanalytics.com> wrote:
>>> Hello,
>>>
>>> I have been unsuccessfully struggling for a programmatical method to
>>> find out whether and where Python is installed.
>>>
>>> The reason is that I am developing a package that depends on python.
>>>
>>> On UNIX/UNIX-like systems I can quite safely assume that python is
>>> directly callable via system if installed.
>>>
>>> My main problems is Windows, though...
>>>
>>> Has anybody faced this problem before?
>>>
>>> Best regards,
>>>
>>> Carlos J. Gil Bellosta
>>> http://www.datanalytics.com
>>>
>>> ______________________________________________
>>> R-devel at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
>
>
> --
> Steve Weston
> REvolution Computing
> One Century Tower | 265 Church Street, Suite 1006
> New Haven, CT  06510
> P: 203-777-7442 x266 | www.revolution-computing.com
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



More information about the R-devel mailing list