I defined a custom toolbox in ArcMap 10.6, the script ran perfectly when I first use it, but ran in error when I use the same script with same parameters again. After I restart ArcMap 10.6, I can use it perfectly again.
When I use the same script in ArcGIS Pro,it run perfectly. I want to know if it is a bug? If so, is it a ArcMap's bug or a networkx package's bug or others? And what can I do?
Here is the error message:
File "******\caculate_network.py", line 7, in <module>
import networkx as nx
File "C:\Python27\ArcGIS10.6\lib\site-packages\networkx\__init__.py", line 128, in <module>
import networkx.drawing
File "C:\Python27\ArcGIS10.6\lib\site-packages\networkx\drawing\__init__.py", line 6, in <module>
from . import nx_pydot
File "C:\Python27\ArcGIS10.6\lib\site-packages\networkx\drawing\nx_pydot.py", line 27, in <module>
from pkg_resources import parse_version
File "C:\Python27\ArcGIS10.6\lib\site-packages\pkg_resources\__init__.py", line 48, in <module>
from pkg_resources.extern import six
File "C:\Python27\ArcGIS10.6\lib\site-packages\pkg_resources\extern\__init__.py", line 45, in load_module
mod = sys.modules[extant]
AttributeError: 'NoneType' object has no attribute 'modules'
-
My only solution is older version of networkx. Bugger.FelixIP– FelixIP2020年03月20日 20:17:53 +00:00Commented Mar 20, 2020 at 20:17
-
1I reduced the version of networkx to 1.11 , the problem is solved! Thank you a lot!user160149– user1601492020年03月21日 04:56:54 +00:00Commented Mar 21, 2020 at 4:56
-
Unless you know how to install it using pip, keep installation package in safe place. Helps when pc breaks.FelixIP– FelixIP2020年03月21日 05:02:51 +00:00Commented Mar 21, 2020 at 5:02
1 Answer 1
I have found a stupid workaround that worked in my case.
I could succesfully run my Python script importing tablib, but only the first run was successful. Until I have tried to import this library in Python window first before running the script. All successive script runs were without any error. Although I do not believe that it is relevant here are the specs:
ArcGIS 10.5.1 v. 7333 (no patches applied), Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)] on win32, tablib version 0.14.0
And the code that have triggered this error
import sys, arcpy, os
import tablib
and the error
Traceback (most recent call last):
File "D:\Data\Test\TestTabLib.py", line 9, in <module>
import tablib
File "C:\Python27\ArcGIS10.5\lib\site-packages\tablib\__init__.py", line 2, in <module>
from pkg_resources import get_distribution, DistributionNotFound
File "C:\Python27\ArcGIS10.5\lib\site-packages\pkg_resources\__init__.py", line 48, in <module>
from pkg_resources.extern import six
File "C:\Python27\ArcGIS10.5\lib\site-packages\pkg_resources\extern\__init__.py", line 44, in load_module
mod = sys.modules[extant]
AttributeError: 'NoneType' object has no attribute 'modules'
-
There is also another option. You can unselect the option Run Python script in process and try to run it again. In my case this failed, however I got the syntax necessary to be able to run it from the command prompt. Then I have copied this string to the command prompt and have executed the code couple of times to test it without the hitch. However, in order to run anything from the command prompt you need to point to the correct python version if you have more than one.Damijan– Damijan2020年07月16日 12:41:20 +00:00Commented Jul 16, 2020 at 12:41