SyntaxError in saved scripts, but not untitled/unsaved scripts

I’m having trouble executing scripts on my machine.

Yesterday I started doing a tutorial with a generative rhino script.
I could execute scripts, debug them, step in and over. But once I saved the file the scripts would no longer execute.

When I run the script I get the following error:

SyntaxError: unexpected token ':'

the script is saved on drive G in folder “G:\1) Documents\ … \”
So I can see why it’s saying G:\1. I just can’t for the life of me figure out why it would not run scripts saved in particular locations, or why it would say the error is on line 1.

What I’ve tried so far:

  • Adding the folder to the Module Search Paths list (doesn’t work when it is, also doesn’t work when it isn’t )
  • Restarting Rhino
  • Restarting Windows
  • Copy pasting the code in a new untitled file (does work!)

Additional info:

  • Rhino is installed on the C:\ drive
  • Rhino version: Version 6 SR12 (6.12.19029.6381, 1/29/2019)

Backslashes in Python “escape” the next character - so normal strings containing file paths with single backslashes do not get interpreted correctly. There are two possible workarounds -

  1. set up your string as a “raw” string (see Python help for more info on this)
  2. use double backslashes

The script doesn’t contain a single backslash (),
In fact Line 1-4, where the error is thrown is:

import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
import random
import Rhino 

I just tried the script on a different computer, and it works fine, even when saved.
So that indicates to me that this is perhaps a setting in rhino, rather than a flaw in the script.

Some additional observations

  • Saving the python script to a different folder on the C-drive resolved the issue (Rhino is installed on the C-drive)
  • Saving the python script to a different folder which includes a space character did not break the script (it continued to work)
  • Saving to different drives also resolved the problem,
  • Saving to the Root of the G: drive resolved the problem
  • Saving to all sorts of folders worked, but it was ultimately one thing that always broken:

Saving a python script to a folder that contains a close round bracket symbol “)” will cause it to generate an error on script execution within Rhino

I expect this to be a bug within the rhino script implementation, where the folder characters aren’t properly being escaped when trying to execute a script.

Dunno, the first post indicated it was a problem with slashes in the file path, hence my response.

So it errors out on the import Rhino line? What error message does it give? Can’t be the same on as in your first post…

I cannot reproduce this here. I made the following to test, saved it as “Hello Rhino”:

import rhinoscriptsyntax as rs
import Rhino

print "Hello Rhino"

I then created folders called “TestFolder()” , “TestFolder)”, "Test Folder) etc… I stored them in various places on my computer, Desktop, Dropbox folder, directly on my D: drive etc., and copied the “Hello Rhino” script into the folder. I then tried to run the script via the built-in editor or via a macro such as:

! _-RunPythonScript "D:\TestFolder)\Hello"

In all cases it worked. No error messages, and “Hello Rhino” was printed to the command line. I even made a copy of the script file and put a second set of parentheses in the filename itself - “Hello Rhino().py” or “Hello Rhino).py” and it still worked…

I didn’t manage to corroborate this theory, everything works here. The fact that it works on some of your machines and not others indicates that it is perhaps a more local problem.

1 Like

Thanks for doing the additional investigation Helvetosaur, I do appreciate the spirit to get to the bottom of this esoteric error.

I just tried the same script you just used to test:

1 import rhinoscriptsyntax as rs
2 import Rhino
4 print "Hello Rhino"

and saved it to c:\1) test, I used a different computer this time and I ran into the same error:

File "", line 1
SyntaxError: unexpected token ':' 

Perhaps we’re running off of different Rhino versions?

Version 6 SR12
(6.12.19029.6381, 1/29/2019)

I’m running the latest SR13 RC (6.13.19046.18041, 15-Feb-19), but that appears not to be the problem.
I am now able to reproduce what you are seeing.

First, my system won’t normally even let me save the file as you titled it directly to the C: drive, it tells me I don’t have permissions. But I did save it to my user folder and there I got the error:


If I remove the parens in the file name, then it runs.

I have no idea where the parsing is going wrong, all I can say is to avoid using such file names… :stuck_out_tongue_closed_eyes: