Rhino 8 python charset_normalizer often fails

@eirannejad I have tried using charset_normalizer on some of my scripts, but they often fail. Do you know why?

I use it like this:

#! python3
# r: charset_normalizer
import charset_normalizer

If I don’t use charset_normalizer and use # -- coding: utf-8 -- instead then the scripts works fine and I can use the norwegian extended characters (æøå).

But I thought maybe charset_normalizer was a better solution for other characters as well.

I assume you have

# r: charset_normalizer

instead of

r: charset_normalizer

Must admit I have not heard of charset_normalizer before.I would go with the utf-8 encoding decoration. The question you need to ask yourself: do you need to cover characters outside utf-8 range? If not then don’t complicate things.

Other than that it would be useful if you explained how charset_normalizer fails…

Absolutely, I use the # r: charset_normalizer, sorry for the typo here.
(I edited the original post now)

It was suggested to me to use it, can’t remember where I picked that up.

Being noob I try stuff and run with it without knowing what I should use :wink:
I’ll rewrite the new scripts to use utf-8 instead.


Another thing, when I run a script on my computer through Python 3 in Rhino and it installs a package, shouldn’t that package be easy to reuse next time I use Rhino?
(If Rhino hasn’t been updated since last time)

Reason I ask is that if I run the script embedded in a button then it often fails unless I start ScriptEditor and run it from there once first. Then I can run the embedded script fine afterwards.

@Holo How are your running the embedded script from a button? The scripting runtime in Rhino does not initialize when Rhino is loaded since not everyone uses it. It initializes when ScriptEditor is opened, or a Script component in Grasshopper is used. If I know how you are running your script from a button I can make it initialize there as well

1 Like

I use this in a button:

-_RunPythonScript (
Paste script here

1 Like

Just a thought, maybe running a python script from a button could be simplified with having it as an option so we don’t have to type in the -_RunPythonScript () thing? (Have a toggle for the different script options):

If it was a function then it could automatically initiate the scripting runtime?
And then it could be intelligent enough to either run a file or the text content.
IF this sounds interesting then please look into the option for running a script from a source like dropbox.
Users install the dropbox folder on different locations. Some use default C: other use D: or move it even further to subfolders.


Are you including #! python3 on top of the script in -_RunPythonScript?

Yes, when I need extra packages. Should I use that all the time now just to be sure?
The script above that I use for SVG export isn’t very advanced so I didn’t include it, but that one works fine though.

If you want to make sure your script is executed with Python 3 then always include the #! python3 specifier at the top. Otherwise the runtime would not know which Python to use and in case of the older _RunPythonScript command, it defaults to IronPython

1 Like