Select to view content in your preferred language

Python Toolbox Broken after Upgrade to Pro 3.2

246
8
2 weeks ago
ZacharyUhlmann1
Frequent Contributor

Displaying the broken path symbol (see screenshot).  Right Click --> Check Syntax yields "No syntax errors".  These were toolboxes that functioned fine from 2.9 thru 3.0.2, and then broke upon upgrading to 3.2.  I continued to 3.3 and 3.4, but still broken.  There are a couple toolboxes that did NOT break.  I can't determine why they survived and the others didn't.

Screenshot 2025-04-10 143452.png

Thanks,

Zach

Tags (3)
0 Kudos
8 Replies
DavidSolari
MVP Regular Contributor

Are you able to cut one of these toolboxes down to a minimum reproduction of the error and then post it here?

0 Kudos
ZacharyUhlmann1
Frequent Contributor

Hi David.  I think it's more efficient to include the entire .pyt as the they are 180 lines and 100 lines respectively.  I can share a GitHub repo with an example of a functioning Python Toolbox and one that doesn't?  For my part, I manually tried reconciling differences between the two and ruled out culprits.  For instance:

  • modules and packages imported
  • This header:

    • # -*- coding: utf-8 -*-

  • Verified that the Python Toolbox datatypes were not deprecated in 3.4 i.e. "Layer", "DEFolder","GPString", etc.
  • the updateParameters method with either version (with or without code blocks in the method): 
# Version 1
def updateParameters(self, parameters):
        return parameters
# Version 2
def updateParameters(self, parameters):
        return

Happy to share the repo.  I could drop 300 lines of python in a response if not.

thanks,

Zach

0 Kudos
DavidSolari
MVP Regular Contributor

A Github repo is great, please post it when you can.

0 Kudos
ZacharyUhlmann1
Frequent Contributor

Does NOT function 

does Function 

Possibly related to the updateParameters method since my two functioning examples (only one shared) have no code block or functionality in that method. 

Thanks David

0 Kudos
DavidSolari
MVP Regular Contributor

Alright, after swapping bits in and out of toolboxes, I managed to get something that looks virtually identical to your code working (attached). I can't even see what significant changes were made using a file diff tool, I have to assume there's some invalid whitespace characters in your source that I Ship of Theseus'd out of there. Let me know if this still gives you trouble.

0 Kudos
ZacharyUhlmann1
Frequent Contributor

Hi @DavidSolari thanks, it worked.  However, I don't know how to apply this to my other .pyt files.  It appears the issue involves line endings, specifically that my files have linux line endings - I think.  I program in PyCharm on a Windows machine, so it could be a setting.  I cannot determine how to simply replace /n with /r/n when converting line endings from Linux to Windows.  Git Diff shows the difference between my files and your as simply the removal of ^M, which is a symbol for a carriage ending used in Windows.  

1) What editor did you use to edit my files?

2) If you get a chance, can you simply open and resave?  I wonder if it's that simple.

Something happened between Pro 3.0.2 and 3.1+ which may require tech support because I'm 6 hours into this troubleshooting.

0 Kudos
DavidSolari
MVP Regular Contributor

Unfortunately I didn't run any bulk edit, in the process of cutting and pasting different chunks around I must have slowly erased all the bad line endings. I use Notepad++ for general text editing and you can use Edit → EOL Conversion to bulk convert a file. If you need to fix a mixed-ending file something like this should work:

import re
bad_file = r"C:\path\to\file"
good_file = r"C:\path\to\output"
with open(bad_file , "r") as f1, open(good_file, "w", newline="\r\n") as f2:
    f2.write(re.sub(r"\r\n?|\n", "\n", f1.read()))
0 Kudos
ZacharyUhlmann1
Frequent Contributor

Thanks @DavidSolari . For clarity, the line endings were my suspicion, but not identified as the culprit - since I haven't solved this yet.  I have tried: 1) matching your file visually (i.e. same number lines, etc.) 2) Involved in 1, I changed triple, single quotes to triple, double quotes in the method descriptions. 3) Tried changing line endings - unsure if executed properly 4) Ran your last code chunk successfully, but didn't fix problem.

You suppose this is eligible for tech support?  The issue was caused by upgrading versions.

much appreciated,

Zach

0 Kudos