Select to view content in your preferred language

Importing arcpy error

8196
7
04-08-2010 07:10 AM
BrianGustafson
Occasional Contributor
when I try and import the arcpy module into python win I get this error.

Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 17, in <module>
    from geoprocessing import gp
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\__init__.py", line 14, in <module>
    from _base import *
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 563, in <module>
    env = GPEnvironments(gp)
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 560, in GPEnvironments
    return GPEnvironment(geoprocessor)
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 506, in __init__
    self._refresh()
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 508, in _refresh
    envset = (set(env for env in self._gp.listEnvironments()))
RuntimeError: NotInitialized


I just instaled the python win 2.6 version after I installed the 10 pre-release.
0 Kudos
7 Replies
KimOllivier
Honored Contributor
ArcGIS 10 puts its own copy of Python26 in a subdirectory of Python26/ArcGIS10.0 (!)
When you install your own Python26 it does not copy the link for ArcGIS python extensions

move Desktop10.pth and the numpy folder back to C:/Python26/Lib/site-packages

and all will be standard and well.

You can then delete the whole ArcGIS10.0 folder so that you only have one version of 2.6 installed
0 Kudos
JohnFell
Frequent Contributor
See the tip at the end of this link.
0 Kudos
RachaelYule
Emerging Contributor
Hi - I'm having the exact same problem as @bmgustafson.
I have followed the advise @kimo posted. However, it didn't seem to work, I'm receiving the error.

I posted my issue in full over on gis.stackexchange.

But have copied my post below:

I'm receiving the following error when importing arcpy using the the IDLE (gui and cmd prompt) and when using pythonwin.

I had removed python26 and python25 from my system and have done a fresh install of ArcGIS 10 and python. Therefore am calling IDLE from here: "C:\Python26\ArcGIS10.0\pythonw.exe"

The Error:

**IDLE 2.6.5
import arcpy Traceback (most recent call last): File "", line 1, in import arcpy File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy__init__.py", line 17, in from geoprocessing import gp File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing__init__.py", line 14, in from _base import * File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing_base.py", line 568, in env = GPEnvironments(gp) File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing_base.py", line 565, in GPEnvironments return GPEnvironment(geoprocessor) File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing_base.py", line 521, in init self._refresh() File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing_base.py", line 523, in _refresh envset = (set(env for env in self._gp.listEnvironments())) RuntimeError: NotInitialized**

EsriUK and Esri tech support have recommended fresh reinstall and registry edits = but this has not worked. I'm waiting on them for a solution.

I've investigated whether it was a module arcpy path issue. There are a couple of links on the Esri forums and on the ArcGIS help regarding paths. Also, a possible related thread on gis.stackexchange.

I followed the advise from 'kimo' on the Esri forum thread. But still the import error.

My system variable (that I've edited) is: PYTHONPATH = "c:\python26";"C:\Python26\ArcGIS10.0";"C:\Python26\ArcGIS10.0\Lib\site-packages";"C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy"

I have checked I have the contents of "C:\Python26\ArcGIS10.0\Lib\site-packages\Desktop10.pth". The contents are: C:\Program Files (x86)\ArcGIS\Desktop10.0\bin C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Scripts

However, the traceback message shows that a .py script is found in the folder: C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy. Therefore, suggests the arcpy module is found by the interpreter but then not initialized(?).

Arcpy can be called from the Python Window within ArcMap and ArcCatalog okay. It is only when called from a Python interpreter that the 'import arcpy' fails. Therefore, arcpy is initalized okay by ArcMap/ArcCatalog, but not IDLE - how can this be?

I previously had an install of python25, then python26 then after that upgraded to ArcGIS 10. Therefore, there was quite a lot of legacy python on my machine. However, I've uninstalled all and registry cleaned using ccleaner.

Can anyone suggest another line of enquiry as I'm not experienced with python enough to solve initialize/runtime errors? I'd like to avoid reinstalling the OS too!

Cheers
Sam
0 Kudos
ScottLarkin
Occasional Contributor
Also look at the following Knowledge Base - Technical Article, which state that this issue also occurs when ArcGIS Desktop and ArcGIS Server are installed on the same machine but only ArcGIS Server is authorized.

http://support.esri.com/es/knowledgebase/techarticles/detail/39029

S
0 Kudos
MennoNijhuis1
Deactivated User
I have had the same problem, both in the office and at a ESRI python course on ESRI PCs. It seems to be an issue with compatibility between pywin and arcpy. I have since switched to pyscripter and haven't switched back.
0 Kudos
BrettElliot
Deactivated User
I was having a similar error to this.

I checked the version of ArcMap installed on the computer, and noticed it hadn't been updated to SP1.

Installing / updating to 10.1 SP1 solved this issue for us.

Cheers,

Brett
0 Kudos
StacyRendall1
Frequent Contributor
You can then delete the whole ArcGIS10.0 folder so that you only have one version of 2.6 installed


Do not delete this folder: ArcCatalog (and maybe ArcMap) require it and will not function correctly without it*. You could test first by moving the Python26\ArcGIS10.0 folder to a new location or renaming it to see if it is OK for your installation.

* - I had issues moving the folder with ArcGIS 10.1 after installing 64-bit background geoprocessing. My system administrator installed the 64-bit ArcGIS Python to C:\Python27, when the 32-bit Python had been installed to D:\Python27. We wanted to move the 32-bit Python but this caused ArcCatalog to crash on opening. Although a number of ESRI registry keys reference the 32-bit Python install path, updating the keys to the new location did not fix the problem.
0 Kudos