Python: Importing and using tools quit working.

2351
9
Jump to solution
11-06-2015 07:30 AM
RandyMcGregor
New Contributor III

I have a script tool that uses several custom tools. It used to work fine, and now fails. Our network was recently massively upgraded, and if this is the issue, than this forum is not the place to solve the problem, but the network drives, etc.. are the same, and all my other data, mxds, etc... are not having trouble being found or working like they used to...

I cannot use arcpy.ImportToolbox. I get an error:

EOL while scanning string literal (NRG Tools.tbx, line
602)

When I use gp.AddToolbox, the toolbox loads, but it can't find the tool:

Can't find tool (Int2SingPt_nrgtools.)

I would appreciate help troubleshooting. I have no idea how to find out what's wrong with line 602 in my toolbox. I actually tried opening it in Word.

I also do not know why it can't find the tool specified. The tool is correctly spelled as is the alias. Basically no tools in this toolbox can be found anymore. The toolbox itself is found and loaded. I get a very clear error if I enter the wrong name/path for the toolbox.

Thank you for any help you may be able to provide.

0 Kudos
1 Solution

Accepted Solutions
RandyMcGregor
New Contributor III

Thank you everybody.

I do believe I think I may have figured out the problem.

Actually, there are two problems:

1) arcpy.ImportToolbox and arcpy.AddToolbox will not load my toolbox. Tech support suggested remaking the toolbox from scratch, which, I must admit, sounds sensible. Apparently, nobody knows how to find this "Line 602" that is causing trouble.

2) The Tool Not Found problem I am getting when I load and run with the gp processor.

It's an alias thing. I think it's THAT simple.

We have a toolbox that is used by everyone in our GIS dept. It has an alias called, "nrgtools."

We copied it to a new location, and intend also to copy the scripts and re-link them. We did not change the alias, so now two toolboxes have the same alilas.

Sometimes, I have both toolboxes in my arcmap document, because I am testing or relinking tools in the new one, but using other tools from the old one that have not yet been relinked in the new one.

I had a eureka moment and changed the alias in the new toolbox to "nrgtools2" and changed the call to those tools in the script to gp.Custom_Tool_nrgtools2...

This seems to have solved the problem.

View solution in original post

0 Kudos
9 Replies
DanPatterson_Retired
MVP Esteemed Contributor

Where was your toolbox stored? It sounds like the path to it is somewhat different.  And if it is a conventional toolbox, were the scripts stored in the same location as the toolbox or elsewhere?

0 Kudos
RandyMcGregor
New Contributor III

Thank you for your message.

The toolbox was copied from its original location and placed in a new location. However, the tool box in the original location won't give up its tools either. It hasn't been deleted and is right where it has been for many years.

I have (hopefully temporarily) completely lost the ability to "borrow" my custom tools in other custom tools. I can run the tools directly with no problem.

The scripts are in a folder called "Scripts" that is in the same folder as the toolbox.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

if the toolbox is one level up in a folder from the script folder you shouldn't have a problem ... ie the scripts folder is relative to the toolbox

\somefolder\mytoolbox.tbx

      .......      \scripts\myscript.py

and not parallel

\somefolder\mytoolbox.tbx

\scripts\myscript.py

0 Kudos
DarrenWiens2
MVP Honored Contributor

Can you provide line 602? It may be helpful to see the preceding line, as well.

0 Kudos
RandyMcGregor
New Contributor III

Do you how a guy would scare up line 602 from a *.tbx file? I'd love to see what that line looks like too!

Thanks for you rmessage.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

For clarification

"EOL while scanning string literal..." etc

comes from a variety of sources, (google yields a load of Stack Overflow examples)

including, mismatched quotes either single, double and or both

Unicode has introduced a load of those errors since there are a variety of Unicode interpretations ie smart quotes

line 602 refers to the line in whatever is trying to read the path (I suspect) to the toolbox.

0 Kudos
DarrenWiens2
MVP Honored Contributor

Ah, I figured line 602 was your importToolbox script line. Nevermind. Best of luck.

0 Kudos
RebeccaStrauch__GISP
MVP Esteemed Contributor

What Dan has mentioned about changed paths might be right.  Right click on the tool in the custom toolbox to get into the properties gift to source tab and the try to navigate to the .py file for each tool.    even if you think they were copied to the same location, maybe it had the machine name as part of the path of something else tgat is keeping the tool from finding the source.  Worth a try anyway.

0 Kudos
RandyMcGregor
New Contributor III

Thank you everybody.

I do believe I think I may have figured out the problem.

Actually, there are two problems:

1) arcpy.ImportToolbox and arcpy.AddToolbox will not load my toolbox. Tech support suggested remaking the toolbox from scratch, which, I must admit, sounds sensible. Apparently, nobody knows how to find this "Line 602" that is causing trouble.

2) The Tool Not Found problem I am getting when I load and run with the gp processor.

It's an alias thing. I think it's THAT simple.

We have a toolbox that is used by everyone in our GIS dept. It has an alias called, "nrgtools."

We copied it to a new location, and intend also to copy the scripts and re-link them. We did not change the alias, so now two toolboxes have the same alilas.

Sometimes, I have both toolboxes in my arcmap document, because I am testing or relinking tools in the new one, but using other tools from the old one that have not yet been relinked in the new one.

I had a eureka moment and changed the alias in the new toolbox to "nrgtools2" and changed the call to those tools in the script to gp.Custom_Tool_nrgtools2...

This seems to have solved the problem.

0 Kudos