No module named pandas
How to get pandas be recognized?
I'm running this script in Mechanical Scripting Console:
import sys sys.path.append(r'C:\\...\\Lib\\site-packages\\pandas') import pandas as pd # output: No module named pandas
Answers
-
The mech scripting console is running the default API that is IronPython. Pandas is not compatible with IronPython, thus you would need to turn on the beta (as of 23.2) feature for CPython and toggle the interpreter to run in that mode.
See other general posts about running CPython and/or numpy, scipy etc….1 -
Hi,
I'm not the original poster, but I'm also trying to use Pandas in Mechanical Scripting.
I'm running Ansys 2024R1 and I've enabled beta CPython, with the interpreter running CPython. I'm able to import numpy and scipy with no issues, via a script or the shell. However, pandas refuses to import. If I try to import via shell, I get the error "No module named 'pandas'"; if I try to import via script, I get the following error:
Traceback (most recent call):
File "Mechanical Scripting Editor", line 1, in
at Python.Runtime.PythonException.ThrowLastAsClrException()
at Python.Runtime.PythonException.ThrowIfIsNull(NewReference& ob)
at Python.Runtime.PyModule.Execute(PyObject script, PyDict locals)
at Python.Runtime.PyModule.Execute[T](PyObject script, PyDict locals)
at Ansys.Mechanical.CPython.CPythonEngine.executeCodeAsFile(String code, String scopeName, String fileName, IDictionary2 args, IDictionary
2 rets)I have pandas installed and working in VSCode.
Is there something I can try to get pandas imported? I know I can use subprocess to run it externally, but it would be very convenient to use it within Mechanical directly.
Thank you!
0 -
@Mike.Thompson said:
The mech scripting console is running the default API that is IronPython. Pandas is not compatible with IronPython, thus you would need to turn on the beta (as of 23.2) feature for CPython and toggle the interpreter to run in that mode.
See other general posts about running CPython and/or numpy, scipy etc….Dear Mike,
I'd also like to use pandas as a means to comfortably import/export Excel data from/to Workbench. Currently, I need to resort to the Microsoft.Office.Interop in CLR from MS.
I got the part about turning on the beta feature, but I don't know how to toggle interpreter mode in Workbench.Thanks for your support
0 -
When you have the beta feature for CPython turned on, there is a drop down toggle in the top right corner of the mechanical scripting console for iron python and CPython.
There is also a property in python code objects for the same type of selection so you can run the code of those objects in the desired interpreter
0