We have an exciting announcement about badges coming in May 2025. Until then, we will temporarily stop issuing new badges for course completions and certifications. However, all completions will be recorded and fulfilled after May 2025.
Platform

Platform

Topics related to optiSLang, HPC, DesignXplorer, Cloud and more.

cx_freeze python error in main script

    • hayri35
      Subscriber
    • Aniket
      Forum Moderator
      can you provide some more information about the issue? Are you using any custom scripts? Ansys employees can not debug user scripts on the forum.
      -Aniket
      How to access Ansys help links
      Guidelines for Posting on Ansys Learning Forum
    • Rachel Gomez
      Subscriber

      Now here are the steps on how to understand and solve that error:

      Read the error from the beginning. The first line tells you the location of the error. So, the error happened in script1.py (that was the name of my script), on line 1. Now you know where the error occurred. For your convenience, you also have the line that caused the error printed out in the second line of the error message.
      Next, look at the error type. In this case, the error type is a SyntaxError. That means you have written something that doesn’t follow the Python syntax rules. So, now you have an idea of what error you are dealing with. For an overview of possible Python error types, you can look here.
      Look at the details of the error. On the right of SyntaxError you have the detailed information about the error. In this case, this information is "invalid syntax"and you also have an arrow character pointing upward. That error is pointing to the colon character. The arrow is trying to say that the colon doesn’t belong there.
      Time to use your logic. Now, the Python interpreter gave you all the information that a robot can give. Now it’s your turn as a human to use your logic to fix the error. So, Python executes a script from top to bottom, line by line, and reads each line from left to right. In this case, it started to read the first line, and it detected round brackets after the assignment operator. That means you are creating a tuple. That’s fine. But then after you write the first item (“Name” in this case). You were supposed to write a comma to separate that item from the next item, but you used a colon instead, so the interpreter is saying that a colon is not syntactically correct to use with round brackets.
      Therefore, you should make up your mind to either write a tuple like:

       data = ("Name", "John", "Surname", "Smith")
      Or a dictionary of key-value pairs, like:

       data = {"Name":"John", "Surname":"Smith".  


      The decision is up to you. In this case, though, I believe the programmer meant to write a dictionary, so I am going to replace the round brackets with curly brackets because I know a dictionary is defined through curly brackets.

      That’s the formula to fix an error. Sometimes though errors are much more complex than this, so in that case copying and pasting the last line of the error (SyntaxError: invalid syntax in this case ) on Google will usually show up forums posts with answers on fixing that particular error. However, that should be the last resort, as it’s better to use your knowledge first.

       

      This may help you,

      Rachel Gomez

Viewing 2 reply threads
  • The topic ‘cx_freeze python error in main script’ is closed to new replies.