0

I am trying to run a python script from R. Which is easy enough to do.

system('python Checkpythonverion.py')

file: Checkpythonverion.py

import sys
print (sys.version)

returns:

2.7.2 |EPD 7.1-2 (64-bit)| (default, Jul  3 2011, 15:34:33) [MSC v.1500 64 bit (AMD64)]

However when I run a code calling the arcpy module (from arcgis)

File: Pythoncode.py

import arcpy
arcpy.env.workspace = r"C:\Student\PythonDesktop10_0\Data\Westerville.gdb"
fc = "Streets"
distanceList = ["100 meters", "200 meters", "400 meters"]
for dist in distanceList:
    outName = fc+"_"+ dist[1]
    arcpy.Buffer_analysis(fc,outName,dist)
    print " Finished Buffer"

Returns

system('python PythonScript.py') Traceback (most recent call last): File "PythonScript.py", line 1, in import arcpy ImportError: No module named arcpy Warning message: running command 'python PythonScript.py' had status 1

I know the reason. Arcmap's arcpy only runs in python26. The issue then is how can I change the default version of python called by the system. I have tried a number of things including: changing HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

from: C:\Python27\python.exe" "%1" %*

to: C:\Python26\ArcGIS10.0\python.exe" "%1" %*

While also changing the user environmental variable "Path"

from: C:\Python27\;C:\Python27\Scripts

to: C:\Python26\ArcGIS10.0\;C:\Python27\Scripts

After which from R:

>system('python Checkpythonverion.py')

still returns:

2.7.2 |EPD 7.1-2 (64-bit)| (default, Jul  3 2011, 15:34:33) [MSC v.1500 64 bit (AMD64)]

Thoughts? It would be great if I could call the version of python I wanted from the R command line. For instance system('python26 file.py'). Running: Windows 7, R 2.15.1 Installed: Python 25,26,27

4

1 回答 1

0

好吧,只是想通了...很简单

system('C:\\Python26\\ArcGIS10.0\\python.exe Checkpythonverion.py')

返回:

2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)]
于 2012-06-29T19:28:19.783 回答