Enable Python installations that were not installed by ArcGIS to access Arcpy functio

المشرف العام

Administrator
طاقم الإدارة
ArcGIS installs its own version of Python that is not officially registered with the system but can in reality be used just like a normal install. I personally prefer just to use this as my primary Python, but it is not always possible. The instructions below can help you let a different Python install access and use Arcpy, for example the Python installed by Python(x,y). Note that:


  • the major versions must match (2.6 for ArcGIS 10.0 and 2.7 for ArcGIS 10.1)
  • the architecture (32 bit or 64 bit) must match (see the start of this post for information on determining Python version and architecture)
  • if you write scripts and use these as script tools within Arc they will use the Python installed by Arc; this means that any libraries you have installed to the other Python, but not installed to the ArcGIS Python, will be inaccessible (causing an ImportError)
Python looks for libraries in certain folders (i.e. the Lib\site-packages\ folder of the install), and when you type import somelibrary it looks for a file by the name of somelibrary.py in these folders. The Arcpy files are actually located in the ArcGIS install folder, in Program Files, but a path file is placed in the Lib\site-packages\ folder that tells Python to also browse through the relevant ArcGIS folders for files when you go to import libraries.

To allow other Python installations to access Arcpy this path file simply needs to be copied from the Lib\site-packages\ folder within the Arc Python installation and placed in the corresponding folder of the non-Arc Python. If you have not installed 64-bit background geoprocessing the file is Desktop10.1.pth; if you have installed it, the file is DTBGGP64.pth.

As an aside: as far as I know it is not possible to move the Python that is installed by ArcGIS. Uninstalling and reinstalling ArcGIS should allow you to change the Python install location, except in the case of some silent network installs.




أكثر...
 
أعلى