Select to view content in your preferred language

'Import arcpy' error (RuntimeError: NotInitialized) when using IDLE

21098
24
02-18-2011 01:37 AM
RachaelYule
Emerging Contributor
ArcGIS Version: ArcGIS 10, Python 2.6.5 Machine: Windows 7 64bit (Intel)

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.

I've posted on GIS.stackexchange too.

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
Tags (2)
0 Kudos
24 Replies
NiklasNorrthon
Frequent Contributor
I might have had a similar problem long time ago in ArcGIS 9.2. I can't recall what it was, but I managed to fix it in the end, and it was something silly. Following are a few questions to answer that might push you in some direction to solve the issue.

Is the error consistent, so you get it all the time?

Does it happen when you execute "import arcpy" interactivly in a fresh IDLE window?

Does it happen from plain python.exe too?

What happens when you do import arcgisscripting?

If that works, what happens when you do gp = arcgisscripting.create()?
0 Kudos
RachaelYule
Emerging Contributor
Hi
Is the error consistent, so you get it all the time?
Yep the the RunTime error is consistent across python.exe, IDLE and pythonwin (was throwing the error before I uninstalled. Note, ArcMap and ArcCatalog can successfully import arcpy.

Does it happen when you execute "import arcpy" interactivly in a fresh IDLE window?
When I via the start menu create an instance of the IDLE, it throws a new error. See screenshot attached.

Does it happen from plain python.exe too?
Yes. I get the same RunTime error from import arcpy. See attached screenshot. No second error message box like with the IDLE as above.

What happens when you do import arcgisscripting?
If that works, what happens when you do gp = arcgisscripting.create()?
Interesting. The two commands above are okay, but I get a RunTime Error:NotInitialsied error when I try to:
gp.toolbox = "analysis"
See attached screenshot. I tried this on a 9.3.1 installation on a different machine = worked okay. I'm not really familar with 9.2/9.3 python geoprocessing module though.

Finally, just to be sure, I've screenshot the shortcut pathway of IDLE. It is:
C:\Python26\ArcGIS10.0\pythonw.exe "C:\Python26\ArcGIS10.0\Lib\idlelib\idle.pyw"
That right?

Does this give anyone any further thoughts?

Cheers - Sam
0 Kudos
JasonScheirer
Esri Alum
This is a licensing issue. What license level are you? Try

import arcview

Before you import arcpy to expicitly set your license level (or arceditor, etc). Make sure your license manager is running.
0 Kudos
RachaelYule
Emerging Contributor
I'm running a single use arcview level licence, which i Authorised 'over the internet' successfully. The ArcGIS Licence Administrator software states ArcView is 'permanent' (I've just reauthorised to be sure).

Make sure your license manager is running
Are you referring to the concurrent licence manager software? Or the local licence utility called "ArcGIS Administrator"?

I get an error when I use 'import arcview'. BUT, then 'import arcpy' does not throw the same RunTime error. So I think it's worked?. See attached screenshot.

But, if I run a .py the script. It will fail as it throws an error on the import arcview statement - can I deal with this using a try/catch on the import arcview statement, to allow the script to run.

Seems odd that on other singleuse ArcGIS 10 installations, I can successfully install the software, authorise the licence, then use import arcpy in the IDLE without requiring the import arcview statement?
0 Kudos
RachaelYule
Emerging Contributor
Further info regarding trying to fix this licence issue...

I've tried authorising (over the internet and via email) my machine with a different single use licence file.

To recap. In addition to the import arcpy error described above, when I try via IDLE:
import arcview

This is the error message:

IDLE 2.6.5     
>>> import arcview

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import arcview
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcview.py", line 18, in <module>
    gp.setProduct("ArcView")
RuntimeError: ERROR 999999: Error executing function

I get the same error when I deauthorise my machine and run import arcview via IDLE.

So it is clear that IDLE and other interpreters do not see that my machine is authorised for a singleuse licence. This possibly explains why when I launch arcMap and import arcpy works okay.

I did have a legacy LM_LICENCE_FILE Environment System Variable referencing a concurrent licence server location. I have deleted this variable - but this has NOT solved the problem.

Are there any other options for setting or connecting to the singleuse licence using python and IDLE? Or is there still a legacy floating licence issue, maybe in the registry, which is incorrectly telling IDLE that I have a floating licence?
0 Kudos
StuartMitchell
Deactivated User
Sam

Did you get any joy with this? I'm having the same problem, although I'm not calling it from IDLE - I'm calling it from within IIS. If I log in as the same user (via a Command Prompt) I don't get the error.

Stuart
0 Kudos
RachaelYule
Emerging Contributor
Hi Stuart

No joy I'm afraid yet. Esri tech support are still looking into this.  It looks like a reinstall of my operating system is the only solution.  I'm not familar at all with IIS, so doubt I can replicate or even comment!  I purely need python for desktop geoprocessing.

The forum replies suggest it is a licence issue i.e. my python interpreter seems to not recognise that I've got an authorised ArcView licence.  All registry keys look correct on my system.

A mystery. Cheers - Sam
0 Kudos
V_StuartFoote
MVP Frequent Contributor
Sam,

Looking at your posts here and on Stack Exchange, I think you have some muddled environment settings.

You want to put C:\Python26\ArcGIS10.0 in your system PATH variable, that gets you to the correct executables from IDLE, PythonWin or the command line.

Your PYTHONPATH could be empty. Or, you could just include the 3 stanzas of your Desktop10.pth file: 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--those paths will then take precedence over the the default search for modules (below the python.exe or pythonw.exe being called).

Finally, since you've uninstalled and installed several versions of Python. At this point, there should be nothing under the C:\Python26 folder except the ArcGIS10.0 folder of the ESRI provided Python 2.6.5 32-bit install. If there is a Lib file there it is a residual of an earlier install and will interfere. It would be a bigger problem if any or your prior Python26 installs were 64-bit.

Also, since you're on 64-bit Windows 7, the Registry path the to 32-bit Python keys are HKLM\SOFTWARE\Wow6432Node\Python If you have a HKLM\SOFTWARE\Python, they would be Keys for a 64-bit install. They also would interfere with the 32-bit install.

Stuart
0 Kudos
RachaelYule
Emerging Contributor
Hi Stuart. Thanks. I've put through the changes you suggest, but still have the arcpy error.

Note, I didn't know how to set the PYTHONPATH variable to 'empty'.  I can't seem to okay the variable edit dialog box when the value is empty.  Therefore, I added the following to the PYTHONPATH (none of the paths are enclosed by double quotes, I don't know if this matters?):

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

I can confirm that the only folder is c:\python26\ArcGIS10.0\ (see attached).

Finally, yep I think I had (in desperation a few weeks ago) installed a 64bit version of python on this machine. I did have a registry stuff within this location: HKLM\SOFTWARE\Python. I have deleted these (hope that was the thing to do).

Also, I've attached a screenshot of: HKLM\SOFTWARE\Wow6432Node\Python.
Can you see I've got legacy stuff from 2.5 and 2.7 versions of python? See attached screenshot for the values.

Delete the non 2.6 keys?
Cheers
0 Kudos