Issues installing pandas on Script Editor

I am trying to use pandas in the new script editor, but I get the following error :

AttributeError: partially initialized module 'pandas' has no attribute '_pandas_datetime_CAPI' (most likely due to a circular import)
Script server execute error:
Traceback (most recent call last):
  File "file:///c:/Users/pablo/Desktop/rhino_code/test-pandas.py", line 2, in <module>
  File "C:\Users\pablo\.rhinocode\py39-rh8\site-envs\default-YVOubeXj\pandas\__init__.py", line 73, in <module>
    from pandas.core.api import (
  File "C:\Users\pablo\.rhinocode\py39-rh8\site-envs\default-YVOubeXj\pandas\core\api.py", line 1, in <module>
    from pandas._libs import (
  File "C:\Users\pablo\.rhinocode\py39-rh8\site-envs\default-YVOubeXj\pandas\_libs\__init__.py", line 18, in <module>
    from pandas._libs.interval import Interval
  File "interval.pyx", line 1, in init pandas._libs.interval
  File "hashtable.pyx", line 1, in init pandas._libs.hashtable
  File "missing.pyx", line 42, in init pandas._libs.missing
AttributeError: partially initialized module 'pandas' has no attribute '_pandas_datetime_CAPI' (most likely due to a circular import)

I can’t find any reference to this issue online; how can I solve this?

I am using Rhino Beta 8.0.23262 2023-09-19

Best,

Pablo

1 Like

please see potential solution

1 Like

i solved it by solving this warning while pip installing the package.
WARNING: The script f2py.exe is installed in ‘c:\users\xxx.rhinocode\py39-rh8\Scripts’ which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

1 Like

Did someone find a solution?

I did add the directory in path ‘c:\users\xxx.rhinocode\py39-rh8\Scripts’ ‘c:\users\xxx.rhinocode\py39-rh8\site-packages’ and I get the same error

AttributeError: partially initialized module ‘pandas’ has no attribute ‘_pandas_datetime_CAPI’ (most likely due to a circular import)

Any updates on this one?

Not sure if you’re using python a GH component or the script editor, but my co-worker and I have had this problem. We have a fix that sometimes works when using pandas in the GH python component.

  1. verify that pandas is installed in the py39-rh8\ folder
  2. Open the Rhino ScriptEditor (command: ScriptEditor) and run the standard import code:
import locale
locale.setlocale(locale.LC_ALL, 'en_US')
import pandas as pd
  1. Open GH as normal, pandas should now import without the annoying error.

Something about loading it in the ScriptEditor First makes it work.

3 Likes

Still have the same issue. Any updates?

Thanks for sharing! This worked form me.

Thank you for the solution. It worked for me too.

1 Like

My default locale is (‘es_ES’, ‘cp1252’), I get it with
import locale
print(locale.getdefaultlocale())
To install pandas, first open an instance in Grasshopper’s Python 3.9 editor with the following:

import local
locale.setlocale(locale.LC_ALL, ‘en_US’)

Execute it
Without closing Grasshopper
After this, install pandas
pip3.9 install pandas

It is convenient to install the Pyarrow library for pandas
pip3.9 install Pyarrow

To use pandas the following is necessary:
import local
locale.setlocale(locale.LC_ALL, ‘en_US’)
import pandas

1 Like

I didn’t need to use pip3.9 directly, just the #r: , but the key for me was

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

both before installation and before import of pandas.

1 Like

Hi,

@eirannejad Is there any update on this?

I’m still facing the issue with the Python3 scripting component for Grashopper, no matter the locale settings.

I’ve tried en_US.UTF-8, en_US.ISO8859-1, en_US, POSIX, C
etc, none of them worked, either before or after installing Pandas, whether C:\Users\...\.rhinocode\py39-rh8\Scripts is added to PATH or not.

Forcing the import from a different environment with # env: my_conda_env doesn’t seem to work either.

The error remains:

File "C:\Users\...\.rhinocode\py39-rh8\site-envs\default-zcVF8413\pandas\__init__.py", line 77, in <module>
    from pandas.core.api import (
File "C:\Users\...\.rhinocode\py39-rh8\site-envs\default-zcVF8413\pandas\core\api.py", line 1, in <module>
    from pandas._libs import (
File "C:\Users\...\.rhinocode\py39-rh8\site-envs\default-zcVF8413\pandas\_libs\__init__.py", line 18, in <module>
    from pandas._libs.interval import Interval
File "interval.pyx", line 1, in init pandas._libs.interval
File "hashtable.pyx", line 1, in init pandas._libs.hashtable
File "missing.pyx", line 40, in init pandas._libs.missing
AttributeError: partially initialized module 'pandas' has no attribute '_pandas_datetime_CAPI' (most likely due to a circular import)

I’m desperate at this point. Please help.

Looking at this deeper today to see if there is anything I can improve more. It would be nice if you can test 8.8 RC and send me the report from RhinoCodeLogs command after opening script editor

2 Likes

Hi @eirannejad

Is there a solution for this? I still have the same problem with Rhino Version 8 SR12
(8.12.24254.14001, 2024-09-10).
AttributeError: partially initialized module 'pandas' has no attribute '_pandas_datetime_CAPI' (most likely due to a circular import)

I added the Script path to the Module Search Path and added the following two line prior to importing pandas in the script:

import locale
locale.setlocale(locale.LC_ALL, 'en_US')

It seemed to work once, but after a Rhino 8 restart I had the same issue again.

I am trying to use pandas 2.1.1. If I use “Open Python 3 Shell” and start python in the powershell window, I can import pandas without any issue.

Hi @eirannejad,

any news on this topic? Will this be fixed in the future?
I updated to Rhino 8 SR 14 (8.14.24325.13001, 2024-11-20) and played around with the pandas import once again. The pandas import works fine within the powershell of Rhino CPython (C:\Users\user_xy\.rhinocode\py39-rh8\python). Below I summarized my observations using pandas 2.1.1 inside the ScriptEditor:

I can use

import locale
locale.setlocale(locale.LC_ALL, 'en_US')

in any python 3 script and execute it once. Afterwards, I can use import pandas in any other script and it works just fine. I do not have to add the C:\Users\user_xy\.rhinocode\py39-rh8\Scripts path to the module search path. Even, if I execute the reload of Python 3, I do not have to add the two locale script lines anymore.

If I forget about executing the two locale script lines prior to import pandas at the beginning of my Rhino python session, I receive the following error:

Traceback (most recent call last):
  File "file:///C:/Users/user_xy/.rhinocode/stage/tgrjxfwu.j2y", line 5, in <module>
  File "C:\Users\user_xy\.rhinocode\py39-rh8\lib\site-packages\pandas\__init__.py", line 73, in <module>
    from pandas.core.api import (
  File "C:\Users\user_xy\.rhinocode\py39-rh8\lib\site-packages\pandas\core\api.py", line 1, in <module>
    from pandas._libs import (
  File "C:\Users\user_xy\.rhinocode\py39-rh8\lib\site-packages\pandas\_libs\__init__.py", line 18, in <module>
    from pandas._libs.interval import Interval
  File "interval.pyx", line 1, in init pandas._libs.interval
  File "hashtable.pyx", line 1, in init pandas._libs.hashtable
  File "missing.pyx", line 1, in init pandas._libs.missing
  File "C:\Users\user_xy\.rhinocode\py39-rh8\lib\site-packages\pandas\_libs\tslibs\__init__.py", line 39, in <module>
    from pandas._libs.tslibs.conversion import localize_pydatetime
  File "conversion.pyx", line 1, in init pandas._libs.tslibs.conversion
  File "offsets.pyx", line 1, in init pandas._libs.tslibs.offsets
  File "timestamps.pyx", line 1, in init pandas._libs.tslibs.timestamps
  File "timedeltas.pyx", line 86, in init pandas._libs.tslibs.timedeltas
  File "fields.pyx", line 7, in init pandas._libs.tslibs.fields
  File "C:\Users\user_xy\.rhinocode\py39-rh8\lib\_strptime.py", line 268, in <module>
    _TimeRE_cache = TimeRE()
  File "C:\Users\user_xy\.rhinocode\py39-rh8\lib\_strptime.py", line 182, in __init__
    self.locale_time = LocaleTime()
  File "C:\Users\user_xy\.rhinocode\py39-rh8\lib\_strptime.py", line 69, in __init__
    self.lang = _getlang()
  File "C:\Users\user_xy\.rhinocode\py39-rh8\lib\_strptime.py", line 28, in _getlang
    return locale.getlocale(locale.LC_TIME)
  File "C:\Users\user_xy\.rhinocode\py39-rh8\lib\locale.py", line 593, in getlocale
    return _parse_localename(localename)
  File "C:\Users\user_xy\.rhinocode\py39-rh8\lib\locale.py", line 501, in _parse_localename
    raise ValueError('unknown locale: %s' % localename)
ValueError: unknown locale: en-US

Afterwards, executing the following lines

import locale
locale.setlocale(locale.LC_ALL, 'en_US')
import pandas

raises the following exception:

Traceback (most recent call last):
  File "file:///C:/Users/user_xy/.rhinocode/stage/tgrjxfwu.j2y", line 5, in <module>
  File "C:\Users\user_xy\.rhinocode\py39-rh8\lib\site-packages\pandas\__init__.py", line 73, in <module>
    from pandas.core.api import (
  File "C:\Users\user_xy\.rhinocode\py39-rh8\lib\site-packages\pandas\core\api.py", line 1, in <module>
    from pandas._libs import (
  File "C:\Users\user_xy\.rhinocode\py39-rh8\lib\site-packages\pandas\_libs\__init__.py", line 18, in <module>
    from pandas._libs.interval import Interval
  File "interval.pyx", line 1, in init pandas._libs.interval
  File "hashtable.pyx", line 1, in init pandas._libs.hashtable
  File "missing.pyx", line 42, in init pandas._libs.missing
AttributeError: partially initialized module 'pandas' has no attribute '_pandas_datetime_CAPI' (most likely due to a circular import)

Reloading the python 3 engine does not help at that state. It only works again, if I restart Rhino 8 and first execute the two ‘locale’ script lines.

@daniel.kowollik Looking into this again now.

Would you mind running RhinoCodeLogs command and find these lines in there

Info 11/26/2024 01:59:14 [RhinoCode] Preparing python locales
Info 11/26/2024 01:59:14 [RhinoCode] Python default locale is 'en_US.cp1252'
Info 11/26/2024 01:59:14 [RhinoCode] Python current locale is 'English_United States.1252'

The python runtime will attempt fixing your locale when editor is being opened. It will report something on these lines if it has made any changes to locale

Hi @eirannejad,

I checked the log file:

Info 26/11/2024 15:52:22 [RhinoCode] Preparing python locales
Info 26/11/2024 15:52:22 [RhinoCode] Python default locale is 'de_DE.cp1252'
Info 26/11/2024 15:52:22 [RhinoCode] Python current locale is 'de_DE.cp1252'
Info 26/11/2024 15:52:22 [RhinoCode] Preparing SSL context

I am currently using the english Rhino 8 version. I think the default installation was german.

1 Like

Hi,

I just tried a fresh english Rhino 8 installation with the identical build on another workstation (no de-DE language folder under Localization C:\Users\user_xy\AppData\Roaming\McNeel\Rhinoceros\8.0\Localization). The windows installation is german. The pandas import produces the same raise and the log file shows the same content as above.

Okay thanks for checking. I will my local and test. Hopefully I can fix the local patcher so this is automatically patched on start

RH-81130 ScriptEditor: Python 3 to set locale before running script

@daniel.kowollik I set my Windows machine’s regional settings to de_DE.cp1252 and tries installing and loading pandas in various ways in Rhino 8.14 and 8.15. All work with no issues so I can not replicate this problem. I will keep this ticket open and will try on different machines.

Hi @eirannejad,

did you install Rhino with the english language pack on the Windows machine with german regional settings?