Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation Order - OCP with VTK and PyVista [pip specific issues] #119

Open
akaszynski opened this issue Aug 31, 2023 · 6 comments
Open

Comments

@akaszynski
Copy link

Ran into an issue recently where tessellation to VTK wasn't working:

import cadquery as cq
import OCP

shape = cq.Workplane().box(1, 1, 1).faces(">Z").hole(0.7).edges().fillet(0.03).val()

vs = OCP.IVtkOCC.IVtkOCC_Shape(shape.wrapped)
sd = OCP.IVtkVTK.IVtkVTK_ShapeData()
sm = OCP.IVtkOCC.IVtkOCC_ShapeMesher()
sm.Build(vs, sd)

pdata = sd.getVtkPolyData()
print(pdata)

Where pdata was output as None. Same issue using the more concise:

import cadquery as cq

shape = cq.Workplane().box(1, 1, 1).faces(">Z").hole(0.7).edges().fillet(0.03).val()
pdata = shape.toVtkPolyData()

After a bit of debugging, turns out the issue will occur if you install vtk with:

pip install vtk==9.2.5.

Since OCP installs the vtkmodules directory, this is silently overwritten when installing vtk.

This is an issue on my end since I'm using cadquery and I'd like to also plot the resulting CAD using pyvista, which depends on the vtk package. The only way I can think to work around this is to install pyvista with no dependencies. If anyone wishes to plot cadquery shapes using pyvista, here's a minimum working example:

pip install cadquery

Followed by installing pyvista without VTK

pip install pyvista --no-deps
pip install scooby matplotlib pooch

This works and the plots look great!

import pyvista as pv
import cadquery as cq

shape = cq.Workplane().box(1, 1, 1).faces(">Z").hole(0.7).edges().fillet(0.03).val()
pdata = pv.wrap(shape.toVtkPolyData())
pdata.plot()

tmp


Ask for the maintainers: Is there any way for OCP to use a pre-compiled version of VTK? Is there any other way of working around this issue?

@whophil
Copy link

whophil commented Aug 31, 2023

@akaszynski - are you installing OCP via conda?

@akaszynski
Copy link
Author

This is all just from good old pip.

@whophil
Copy link

whophil commented Aug 31, 2023

@akaszynski I see. This may not be an adequate solution for you, but this should "just work" if you use conda. I certainly understand the many reasons you might not want to use conda.

This seems to be mainly an issue with the wheels, whose builds are handled in a separate project - https://github.com/CadQuery/ocp-build-system/.

Cross-referencing your issue there (CadQuery/ocp-build-system#14)

@akaszynski
Copy link
Author

Yep, I recall opening that there, but reposted here so that others could know there's a solution.

Sadly, conda isn't an option for me at this point due to issues repackaging with pyinstaller. One solution I thought of was creating a simple fork of pyvista called pyvista-no-vtk that installs pyvista without installing vtk. PyVista (for my use case) still works out of the box since we use only vtkmodules.

@akaszynski
Copy link
Author

Here's another (albeit still non-ideal) hack. Install everything normally and then proceed to reinstall cadquery after deleting the vtkmodules directory:

pip install pyvista cadquery
rm -rf ~/.venv311/lib/python3.11/site-packages/vtkmodules  # will need to modify the directory
pip install cadquery --force-reinstall

@adam-urbanczyk adam-urbanczyk changed the title Installation Order - OCP with VTK and PyVista Installation Order - OCP with VTK and PyVista [pip specific issues] Aug 31, 2023
@adam-urbanczyk
Copy link
Member

Yep, I recall opening that there, but reposted here so that others could know there's a solution.

Thanks for sharing, noted. Still, the advised installation method is conda.

Sadly, conda isn't an option for me at this point due to issues repackaging with pyinstaller. One solution I thought of was creating a simple fork of pyvista called pyvista-no-vtk that installs pyvista without installing vtk. PyVista (for my use case) still works out of the box since we use only vtkmodules.

There should not be any fundamental issue pyinstaller and conda. BTW: recently for CQ-editor, we switched to constructor. Maybe something to try?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants