I have successfully installed numpy and pandas in the Rhino Python path using pip install (CMD). I am able to import and use numpy in the Rhino script editor without any issues. However, when I attempt to import pandas, it seems to be causing some problems.
The code error is as follows:
[0 1 2 3 4 5 6 7 8 9]
Traceback (most recent call last):
File “file:///G:/%E5%90%8C%E6%AD%A5%E8%B5%84%E6%96%99/OneDrive%20-%20lyrics5816/%E8%AE%BE%E8%AE%A1%E7%B4%A0%E6%9D%90/GH/%E4%B8%AA%E4%BA%BA%E7%A0%94%E7%A9%B6/python/pandas%20test.py”, line 5, in
File “C:\Users\97471.rhinocode\py39-rh8\lib\site-packages\pandas_init_.py”, line 73, in
from pandas.core.api import (
File “C:\Users\97471.rhinocode\py39-rh8\lib\site-packages\pandas\core\api.py”, line 1, in
from pandas.libs import (
File "C:\Users\97471.rhinocode\py39-rh8\lib\site-packages\pandas_libs_init.py", line 18, in
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)
Perhaps rename your script from pandas test.py to say my_test.py. Also, if that still fails, perhaps try resetting your Python 3 runtime (through the Tools > Advanced menu of the script editor).
Ive installed successfully openpyxl with whl. file, download from openpyxl · PyPI, just copy and paste into the folder like this: /Users/xxx/.rhinocode/py39-rh8/lib/python3.9/site-packages.
I have a same problem, and Though I tried @nathanletwory 's tips but it didn’t work for me.
I hope this could be solved soon, because I was thrilled to use pandas in Rhino8.
I solved this problem. You should add C:\Users\User.rhinocode\py39-rh8\Scripts to Path Environment. If not, Rhino python find pandas somewhere else(maybe my local pandas) and It occur cyclic errors.
#! python3
#r: psycopg2,pandas,openpyxl
import rhinoscriptsyntax as rs
import scriptcontext as sc
import openpyxl
import System
import System.Collections.Generic
import Rhino
import psycopg2
# import locale
# locale.setlocale(locale.LC_ALL, 'en_US')
import pandas as pd
it return a error message:
AttributeError: partially initialized module ‘pandas’ has no attribute ‘_pandas_datetime_CAPI’ (most likely due to a circular import)
I had to set local before pandas in this code. In yours it was commented out, is that for a reason?
#! python3
# r: pandas
import rhinoscriptsyntax as rs
import scriptcontext as sc
import math
import System
import System.Collections.Generic
import Rhino
import locale
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
import rhinoscriptsyntax as rs
import json
import pandas as pd
#prompt the user for a file to import
filter = "JSON file (*.json)|*.json|All Files (*.*)|*.*||"
filename = rs.OpenFileName("Open JSON File", filter)
#Read JSON data into the datastore variable
if filename:
with open(filename, 'r') as f:
datastore = json.load(f)
df = pd.DataFrame(datastore)
csv_file = df.to_csv()
print(csv_file)
Does that solve the problem?
This other thread seems to say that the locale must be locale.LC_ALL, 'en_US.UTF-8'
This is a library order problem. For instance Pandas needs a specific version of numpy during the Pip install phase.
#! python3
#r: pandas, openpyxl, psycopg2
import rhinoscriptsyntax as rs
import scriptcontext as sc
import System
import System.Collections.Generic
import Rhino
import locale
locale.setlocale(locale.LC_ALL, 'en_US')
import openpyxl
import psycopg2
import pandas as pd
print(pd.__version__)
By removing the other libraries first and getting pandas to work properly was the first step. Then the other two libraries can be added to install after pandas
I have been seeing this lately where PIP installs multiple libraries and there are specific internal dependencies that can conflict with other libraries. I think both Pandas and Openyxl can be a specific about numpy and scipy libraries they need.
Is it possible to specify a virtual environment location where the installation of Pandas works? Because I use Pandas in many scripts that utilize virtual environments, and it works perfectly fine.
thanks!