pydpf AttributeError `'dict' object has no attribute 'return_arrays'`

Options
James Derrick
James Derrick Administrator, Employee Posts: 248
First Anniversary Solution Developer Community of Practice Member Ansys Employee 5 Up Votes
admin

I downloaded Ansys Student and pydpf and tried to run an example.

This example, specifically: https://dpf.docs.pyansys.com/version/stable/examples/02-modal_analyses/01-plot_and_animate_modes.html#sphx-glr-examples-02-modal-analyses-01-plot-and-animate-modes-py

I have Ansys Student 24R1 and

ansys-dpf-composites==0.4.0
ansys-dpf-core==0.10.1
ansys-dpf-gate==0.4.1
ansys-dpf-gatebin==0.4.1
ansys-dpf-post==0.6.0

The error trace looks like this

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[3], line 9
      6 unit = freq_support.time_frequencies.unit
      8 # For each ID in the scoping
----> 9 for freq_set in freq_scoping:
     10     # Get the associated frequency in the time_freq_support
     11     freq = freq_support.get_frequency(cumulative_index=freq_set - 1)
     12     # Get the associated mode shape as a displacement field

File ~\OneDrive - ANSYS, Inc\Documents\GitHub\PyConLabSetup\venv\Lib\site-packages\ansys\dpf\core\scoping.py:312, in Scoping.__iter__(self)
    311 def __iter__(self):
--> 312     return self.ids.__iter__()

File ~\OneDrive - ANSYS, Inc\Documents\GitHub\PyConLabSetup\venv\Lib\site-packages\ansys\dpf\core\scoping.py:279, in Scoping.ids(self)
    261 @property
    262 def ids(self):
    263     """Retrieve a list of IDs in the scoping.
    264 
    265     Returns
   (...)
    277     Print a progress bar.
    278     """
--> 279     return self._get_ids()

File ~\OneDrive - ANSYS, Inc\Documents\GitHub\PyConLabSetup\venv\Lib\site-packages\ansys\dpf\core\scoping.py:172, in Scoping._get_ids(self, np_array)
    169 if np_array == None:
    170     from ansys.dpf.core import settings
--> 172     np_array = settings.get_runtime_client_config(self._server).return_arrays
    173 try:
    174     vec = dpf_vector.DPFVectorInt(
    175         client=self._server.client,
    176         api=self._server.get_api_for_type(
   (...)
    179         ),
    180     )

AttributeError: 'dict' object has no attribute 'return_arrays'

Have I found a bug or done something wrong?

Tagged:

Best Answer

  • James Derrick
    James Derrick Administrator, Employee Posts: 248
    First Anniversary Solution Developer Community of Practice Member Ansys Employee 5 Up Votes
    admin
    Answer ✓
    Options

    OK Once I installed ansys-dpf-core==0.11.0 it gave a new self-explanatory error and once obeyed, it all worked!

    E       ImportError: Error during import of ansys-dpf-core:
    E       detected one of ['ansys-dpf-gatebin', 'ansys-dpf-gate', 'ansys-grpc-dpf'] installed. The current version of ansys-dpf-core requires uninstalling these previous dependencies to run correctly.
    

Answers

  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 67
    First Anniversary Solution Developer Community of Practice Member Ansys Employee 5 Likes
    Options

    This is due to discontinuation of ansys-dpf-gate module. Since this virtual environment was still having dpf-gate client, the dpf core ended up using older dpf gate source code.

    With recent versions, dpf-gate is shipped with ansys-dpf-core itself. if you still have dpf-gate then it would throw warning.

    You can use only these, if you want to use specific version of clients. Else, use latest versions.
    ansys-dpf-composites==0.4.0
    ansys-dpf-core==0.10.1
    ansys-dpf-post==0.6.0

  • James Derrick
    James Derrick Administrator, Employee Posts: 248
    First Anniversary Solution Developer Community of Practice Member Ansys Employee 5 Up Votes
    admin
    edited April 4
    Options

    @Rajesh Meena Thanks for your input, I'm afraid this hasn't fixed it for me. I did a completely clean venv with Python and just installed ansys-dpf-core and jupyterlab then tried to run the example again (this should have worked).

    It did not because

    File ~\dpfvenv\Lib\site-packages\ansys\dpf\core\plotter.py:44, in _PyVistaPlotter.__init__(self, **kwargs)
         42 def __init__(self, **kwargs):
         43     # Import pyvista
    ---> 44     from ansys.dpf.core.vtk_helper import PyVistaImportError
         46     try:
         47         import pyvista as pv
    
    File ~\dpfvenv\Lib\site-packages\ansys\dpf\core\vtk_helper.py:2
          1 import numpy as np
    ----> 2 import pyvista as pv
          3 import ansys.dpf.core as dpf
          4 from ansys.dpf.core import errors
    
    ModuleNotFoundError: No module named 'pyvista'
    
  • James Derrick
    James Derrick Administrator, Employee Posts: 248
    First Anniversary Solution Developer Community of Practice Member Ansys Employee 5 Up Votes
    admin
    Options

    It did work once pyvista was installed, however.

  • KristianHansen
    KristianHansen Member Posts: 7
    Name Dropper First Comment
    Options

    @James Derrick said:
    OK Once I installed ansys-dpf-core==0.11.0 it gave a new self-explanatory error and once obeyed, it all worked!

    E       ImportError: Error during import of ansys-dpf-core:
    E       detected one of ['ansys-dpf-gatebin', 'ansys-dpf-gate', 'ansys-grpc-dpf'] installed. The current version of ansys-dpf-core requires uninstalling these previous dependencies to run correctly.
    

    I am having the same issue!

    I have just performed a fresh install of ANSYS2024R1, and setup a new venv.
    In this venv i have run the following commands:

    pip install pyansys
    pip install spyder

    When doing this, i encountered the error "AttributeError: 'dict' object has no attribute 'return_arrays'"

    To solve the issue, i updated to ansys-dpf-core==0.11.0:

    pip install --force-reinstall -v "ansys-dpf-core==0.11.0"

    And I recieved the same self-explanatory error you encountered:

    E ImportError: Error during import of ansys-dpf-core:
    E detected one of ['ansys-dpf-gatebin', 'ansys-dpf-gate', 'ansys-grpc-dpf'] installed. The current version of ansys-dpf-core requires uninstalling these previous dependencies to run correctly.

    So solve the issue, i performed:

    pip uninstall ansys-dpf-gatebin
    pip uninstall ansys-dpf-gate
    pip uninstall ansys-grpc-dpf

    Now i just receive the following error:

    ModuleNotFoundError: No module named 'ansys.dpf.gate'

    ... Obviously i just removed ansys.dpf.gate, but I thought that was the point? :cold_sweat:
    Can anyone please help me?

  • KristianHansen
    KristianHansen Member Posts: 7
    Name Dropper First Comment
    Options

    Update:
    I started over... New venv installed pyansys=2024.1.2

    got error: "AttributeError: 'dict' object has no attribute 'return_arrays'"

    updated dpf core: pip install ansys-dpf-core==0.11.0

    got error: E detected one of ['ansys-dpf-gatebin', 'ansys-dpf-gate', 'ansys-grpc-dpf'] installed...

    reinstalled old dpf core: pip install ansys-dpf-core==0.10.1

    Now everything works...

    TLDR; in my case, simply forcing the install of dpf core 0.10.1 fixed it...

    pip install ansys-dpf-core==0.10.1

  • Paul Profizi
    Paul Profizi Member, Employee Posts: 10
    5 Likes First Comment First Anniversary First Answer
    edited April 18
    Options

    Hello everyone,
    Just to confirm, ansys-dpf-core 0.10.1 should not have ansys-dpf-gate, ansys-dpf-gatebin or ansys-grpc-dpf installed along with it.
    This is why 0.11.0 now raises an Error.
    ansys-dpf-core 0.10.1 installed in a fresh venv will not install ansys-dpf-gate, gatebin or grpc-dpf, and should not raise the initial issue anymore.

    The issue you got hen installing everything from the start is probably due to the "pyansys" module still marking ansys-dpf-gate as required.

  • James Derrick
    James Derrick Administrator, Employee Posts: 248
    First Anniversary Solution Developer Community of Practice Member Ansys Employee 5 Up Votes
    admin
    Options

    Hi @Paul Profizi that's good to know! I think I ended up in this situation after doing pip install pyansys so do you know if the bundle has also fixed it?

  • Paul Profizi
    Paul Profizi Member, Employee Posts: 10
    5 Likes First Comment First Anniversary First Answer
    Options

    @James Derrick said:
    @Rajesh Meena Thanks for your input, I'm afraid this hasn't fixed it for me. I did a completely clean venv with Python and just installed ansys-dpf-core and jupyterlab then tried to run the example again (this should have worked).

    It did not because

    File ~\dpfvenv\Lib\site-packages\ansys\dpf\core\plotter.py:44, in _PyVistaPlotter.__init__(self, **kwargs)
         42 def __init__(self, **kwargs):
         43     # Import pyvista
    ---> 44     from ansys.dpf.core.vtk_helper import PyVistaImportError
         46     try:
         47         import pyvista as pv
    
    File ~\dpfvenv\Lib\site-packages\ansys\dpf\core\vtk_helper.py:2
          1 import numpy as np
    ----> 2 import pyvista as pv
          3 import ansys.dpf.core as dpf
          4 from ansys.dpf.core import errors
    
    ModuleNotFoundError: No module named 'pyvista'
    

    @James Derrick ah you found an error. This is supposed to raise an explicit error telling the user to install plotting dependencies to use plotting features. Will fix.

  • Paul Profizi
    Paul Profizi Member, Employee Posts: 10
    5 Likes First Comment First Anniversary First Answer
    Options

    @James Derrick said:
    Hi @Paul Profizi that's good to know! I think I ended up in this situation after doing pip install pyansys so do you know if the bundle has also fixed it?

    I just checked and the latest PyAnsys meta package indeed contains ansys-dpf-gate as a dependency along with ansys-dpf-core 0.10.1, which is wrong. Will tell them to fix and release.