1

I'm following this guide http://pro.arcgis.com/en/pro-app/arcpy/geoprocessing_and_python/extending-geoprocessing-through-python-modules.htm

I got it to work on arcmap 10.6 (desktop) when the toolbox is in the same folder as the module (src/foo/foo.py). But when I move the toolbox into src/foo/esri/toolboxes, the toolbox has a red x on it in arccatalog.

Inside the toolbox I've tried:

  • import foo.foo
  • import foo
  • import foo from foo

When i right click on toolbox and "check syntax" I keep getting the error "ImportError: No module named foo"

Reading up on google it sounds like i may need to do something with sys.path.append... but I've tried tons of copied and pasted solutions to no avail.

Other people have said I have to type in the path manually, but that's a problem since i'm hoping to share this to others.

I tried building it, and installing it, and it doesn't show up in arctoolbox. When I have the toolbox in the foo folder, it does show up in arctoolbox after install.

I'm out of things to try and looking for help!

I am creating the project in PyDev Eclipse, and there are no syntax errors or problems with imports.

  • Just wanted to add that i'm writing scripts in PyDev eclipse, and there are no errors flagged in the entire project. – Adam B May 4 '18 at 7:22
  • 1
    Read up on the module search path and how to set it. – user2856 May 4 '18 at 10:32
  • This might help you stackoverflow.com/questions/50499/… in conjunction with the comment by @Luke – Michael Stimson May 4 '18 at 12:57
  • @Luke I edited my question to add the comment in, sorry about that. Can you please tell my the question is on hold, or if there's any changes I can make to improve it? Thanks. – Adam B May 4 '18 at 15:43
  • @AdamB The community could have been a bit more helpful by explaining how this is offtopic, instead of just voting. The core of your problem is one script cannot find another script to import. While sure, you're using ArcGIS and its GIS software indicating the problem. The core part of the problem is specific to importing modules within Python. ArcGIS "runs" a PYT to discover if there are any issues. If you were to run your project in Eclipse it should error the same way as you see in ArcGIS. Luke & Michael have provided some good pointers on the core concepts of modules and importing – KHibma May 4 '18 at 16:07
1

As commented by @KHibma:

The core of your problem is one script cannot find another script to import. While sure, you're using ArcGIS and its GIS software indicating the problem. The core part of the problem is specific to importing modules within Python. ArcGIS "runs" a PYT to discover if there are any issues. If you were to run your project in Eclipse it should error the same way as you see in ArcGIS. Luke & Michael have provided some good pointers on the core concepts of modules and importing

@Luke's comments were:

Read up on the module search path and how to set it.

and

I would also think about reorganising your code and having the toolbox at the top level, something like https://gis.stackexchange.com/a/43213/2856 and see also possible duplicate Q. https://gis.stackexchange.com/a/75942/2856

while @MichaelStimson commented that:

This might help you https://stackoverflow.com/questions/50499/how-do-i-get-the-path-and-name-of-the-file-that-is-currently-executing

I note that you have commented that:

Based on the links, [you]'ve solved the problem by putting sys.path.append(path to my src folder).

I should also point out that you seem to be using ArcPy with ArcMap but you are referring to ArcGIS Pro documentation which is not always the same.

  • Yes that’s right, do you know if there’s any danger leaving that line in the toolbox once I distribute the toolbox? Since that directory won’t exist on others’ machines – Adam B May 15 '18 at 3:32
  • Not without testing, and this is one where I'm unable to volunteer time to test. – PolyGeo May 15 '18 at 3:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.