Error in Rhino 8 SR31 when using pandas: unknown locale: en-US [7:1]

,

In Grasshopper when using pandas in a Python3 component, I get an error “1. Error executing script: unknown locale: en-US [7:1]” and have confirmed same behaviour from clients.

The fix:
1: Open Rhino
2: Run ‘ScriptEditor’ command
3: Make new Python Script.
4: Run this code:

import locale
locale.setlocale(locale.LC_ALL, ‘en_US’)
import pandas as pd

This is only after SR31

I believe i’m running into the same issue on my client’s PC after update.

I was getting this error in the GH python component:

1. Error running script: partially initialized module ‘pandas’ has no attribute ‘_pandas_datetime_CAPI’ (most likely due to a circular import) [3:1]

After re-installing pandas and numpy libraries through the Python script editor in Rhino is was getting the locale issue. After resolving this with a snippet from another post i am getting the initial Error again.

My client is on Windows btw

This is the snippet and possible solution i found but i see you already have it in your code

@eirannejad

Could you have a look at this please?

Updated from 8.31 to 8.32 but the problem persists

@Calcman This is a known issue with pandas on Windows. The underlying problem is that Windows locale names are not very standard and python locale module sometimes fails at processing them.

Run this script and tell me what it prints:

import locale
print(locale.getlocale())

This is what it prints on my machine ('English_United States', '1252')

Also maybe try this other snippet that adds .UTF-8 to the locale. See if this works.

import locale
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
import pandas

Hi Ehsan, thank you for your help. I’m getting the following from the script environment:

Traceback (most recent call last):
File “file:///C:/Users/Asus/.rhinocode/stage/5uq5u5yf.c5y”, line 2, in
NameError: name ‘locale’ is not defined

The other snippet you shared was already part of my script. It has worked well for about two years. The current situation happened only after update to v8.31

My code:

# r: gsheets, pygsheets, pandas

#https://erikrood.com/Posts/py_gsheets.html
import pygsheets

import os
path = os.path.dirname(ghdoc.Path)

#https://discourse.mcneel.com/t/issues-installing-pandas-on-script-editor/166071/10
import locale
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
import pandas as pd
import scriptcontext as sc
from io import StringIO

#authorization
gc = sc.sticky['authorization']

naam = naam

index = 5

# Define a function to get CSV from a specific sheet tab
def get_csv_from_tab(sh, index):
    wks = sh[index]
    data = pd.DataFrame(wks.get_all_records())
    #csv_buffer = StringIO()
    return data.to_csv(sep=';', index=False)
    #return csv_buffer.getvalue()

# Open the Google spreadsheet
sh = gc.open(naam)

# Manually select the tabs by index and store their CSVs in separate variables
then here are a few lines of get_csv_from_tab


I was able to resolve this with:

rhino_startup.py

import locale

try:
locale.setlocale(locale.LC_ALL, ‘’)
except:
pass

try:
current = locale.setlocale(locale.LC_ALL, None)

if '-' in current:
    locale.setlocale(
        locale.LC_ALL,
        current.replace('-', '_')
    )

except:
pass

Ya I had a script like this by default to fix Windows-style locale names but that ended up messing up other locale based stuff. I am glad this works for you. Thanks for the update.

Hi Ehsan, how can we get a permanent fix for this. It means pandas is not robust to include in any tools in Rhino?