scopatz/pyembree

conda-forge installation in win10 env?

yscoffee opened this issue Β· 37 comments

Hi
I am wondering that does the installation available in win10 x64 environment?

some logs:

$conda config --add channels conda-forge
$ conda install -c conda-forge pyembree
(base) conda install pyembree
Solving environment: failed
PackagesNotFoundError: The following packages are not available from current channels:
  - pyembree

For what it's worth it's quite easy to install by hand on Windows 10. The following steps work for me with Anaconda:

  • git clone https://github.com/scopatz/pyembree.git
  • cd pyembree
  • conda install cython numpy
  • conda install -c conda-forge embree
  • set INCLUDE=%CONDA_PREFIX%\Library\include
  • set LIB=%CONDA_PREFIX%\Library\lib
  • python setup.py install --prefix=%CONDA_PREFIX%

Hi,
I am following the steps to install pyembree in windows 10.

These commands worked well.
$git clone https://github.com/scopatz/pyembree.git
$cd pyembree
$conda install cython numpy
$conda install -c conda-forge embree
$set INCLUDE=%CONDA_PREFIX%\Library\include
$set LIB=%CONDA_PREFIX%\Library\lib

and I run the last command, I got this error.
$python setup.py install --prefix=%CONDA_PREFIX%
...
pyembree\mesh_construction.cpp(633): fatal error C1083: Cannot open include file: 'embree2/rtcore.h': No such file or directory

Does anyone have an idea what would be the problem?
Thank you.

It would probably be best to put in a PR to the pyembree-feedstock for building on windows

For what it's worth it's quite easy to install by hand on Windows 10. The following steps work for me with Anaconda:

git clone https://github.com/scopatz/pyembree.git
cd pyembree
conda install cython numpy
conda install -c conda-forge embree
set INCLUDE=%CONDA_PREFIX%\Library\include
set LIB=%CONDA_PREFIX%\Library\lib
python setup.py install --prefix=%CONDA_PREFIX%

This didn't work for me at first, but it worked once I made sure to clone pyembree into \Lib\site-packages\ of my environment.

As I said, adding that to the feedstock would be awesome!

I followed This instruction.

Environment:
OS: Win 8.1 x64
Compiler: from Visual studio 2015

  1. When I executed setup.py, I met with this error:
    fatal error C1083: Cannot open include file: 'io.h': No such file or directory.
    StackOverFlow solution.
    I installed Win 10 SDK (Though I’m using Win 8) and then this error disappeared.

  2. Afterwards, I met with this error:
    fatal error LNK1158: cannot run β€˜rc.exe’
    StackOverFlow solution.
    I copy rc.exe and rcdll.dll from Win 10 SDK’s dir (C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64\) to Visual Studio’s dir (C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\).

Finally, I successfully installed Pyembree.

For what it's worth it's quite easy to install by hand on Windows 10. The following steps work for me with Anaconda:

  • git clone https://github.com/scopatz/pyembree.git
  • cd pyembree
  • conda install cython numpy
  • conda install -c conda-forge embree
  • set INCLUDE=%CONDA_PREFIX%\Library\include
  • set LIB=%CONDA_PREFIX%\Library\lib
  • python setup.py install --prefix=%CONDA_PREFIX%

Still works in 2020, thank you

Hi,
I am following the steps to install pyembree in windows 10.

These commands worked well.
$git clone https://github.com/scopatz/pyembree.git
$cd pyembree
$conda install cython numpy
$conda install -c conda-forge embree
$set INCLUDE=%CONDA_PREFIX%\Library\include
$set LIB=%CONDA_PREFIX%\Library\lib

and I run the last command, I got this error.
$python setup.py install --prefix=%CONDA_PREFIX%
...
pyembree\mesh_construction.cpp(633): fatal error C1083: Cannot open include file: 'embree2/rtcore.h': No such file or directory

Does anyone have an idea what would be the problem?
Thank you.

I have the same problem, how do you fix that?

Hi,
I am following the steps to install pyembree in windows 10.
These commands worked well.
$git clone https://github.com/scopatz/pyembree.git
$cd pyembree
$conda install cython numpy
$conda install -c conda-forge embree
$set INCLUDE=%CONDA_PREFIX%\Library\include
$set LIB=%CONDA_PREFIX%\Library\lib
and I run the last command, I got this error.
$python setup.py install --prefix=%CONDA_PREFIX%
...
pyembree\mesh_construction.cpp(633): fatal error C1083: Cannot open include file: 'embree2/rtcore.h': No such file or directory
Does anyone have an idea what would be the problem?
Thank you.

I have the same problem, how do you fix that?

I got the same issue, anyone could help? Thanks a lot!

his didn't work for me at first, but it worked once I made sure to clone pyembree into \Lib\site-packages\ of my environment.

The issue has been solved, I got hint from this thread.

his didn't work for me at first, but it worked once I made sure to clone pyembree into \Lib\site-packages\ of my environment.

The issue has been solved, I got hint from this thread.

Hi, how did you solve it?

his didn't work for me at first, but it worked once I made sure to clone pyembree into \Lib\site-packages\ of my environment.

The issue has been solved, I got hint from this thread.

Hi, how did you solve it?

This didn't work for me either, I also made sure that Win 10 SDK is up to date. Does anyone know how to solve this issue?

  1. Make sure you put or clone pyembree in "{yourpath}\anaconda3\Lib\site-packages"
  2. Run the commands in "Anaconda Prompt", for me running in terminal/git bash didn't work

For me it worked. Follow the order,

  1. Add environment variable (not a path) as CONDA_PREFIX put the folder to miniconda or anaconda (for me "C:\ProgramData\Miniconda3")
  2. Put the clone like @kaminwong mentioned
  3. Goto pyembree folder
  4. Open a cmd instead Powershell (open Powershell admin console inside the pyembree folder and type "cmd")
  5. Follow @dwastberg 's steps. It will work.

Following @sasadara 's steps broke something in the environment. On importing an unrelated package with a DLL-dependency, I get an error in ctypes during DLL loading.

Following @sasadara 's steps broke something in the environment. On importing an unrelated package with a DLL-dependency, I get an error in ctypes during DLL loading.

Did you resolve it?

Following @sasadara 's steps broke something in the environment. On importing an unrelated package with a DLL-dependency, I get an error in ctypes during DLL loading.

Did you resolve it?

No, but I could simply set up the environment from scratch.

I was able to install this in the normal Conda PowerShell without any cloning or switching shells. You can set environmental variables like this in PowerShell and then compile/install (and I just hardcoded the full paths to avoid other problems):

(your_env_name) PS D:\Dev\pyembree> $env:PYTHONPATH = "C:\Users\Public\Conda\envs\your_env_name\lib\site-packages"
(your_env_name) PS D:\Dev\pyembree> $env:INCLUDE = "C:\Users\Public\Conda\envs\your_env_name\Library\include"
(your_env_name) PS D:\Dev\pyembree> $env:LIB = "C:\Users\Public\Conda\envs\your_env_name\Library\lib"
(your_env_name) PS D:\Dev\pyembree> python setup.py install --prefix=C:\Users\Public\Conda\envs\your_env_name\

Hope this is helpful to someone, I wasted about an hour on it :)

@scopatz How do we put in a PR to the pyembree-feedstock for building on windows? Do I create a new issue at the conda-forge/anaconda-client-feedstock GitHub page? Let's get this going!

Also, can we make add support for installing this via poetry? I prefer to use it over conda.

@scopatz I created a new issue here. Let's get a lot of thumbs up on this so we can get them to add embree/pyembree support!

Installation Instructions

Tested on:

OS: Windows 10 x64 Professional, Build 1909
Python: 3.8.5 x64
Date: 31-JULY-2021

Steps

  1. Install Microsoft Visual Studio 2017 Build Tools and the Windows 10 SDK. These are required for building cython code.

(NOTE: FYI, Microsoft Visual Studio version numbers are not the same as Microsoft Visual C++ Compiler versions. MSVCv14X x64/x86 build tools are required for Python 3.8. Installing the Visual Studio 2017 Build Tools with the Windows 10 SDK. If you wish to install Visual Studio 2017, select the Desktop development with C++ Workload and make sure the required Windows 10 SDK build tool is selected under Individual Components. Refer to the Python Wiki for the right build tool versions to install).

  1. Install vcpkg in C:\vcpkg and add the path to your System Environment Variables. Be sure to bootstrap and integrate vcpkg:
cd C:\vcpkg
git clone https://github.com/Microsoft/vcpkg.git
bootstrap-vcpkg.bat
vcpkg integrate install

Alternatively, you can download and install the embree-2.17.7.x64.msi Installer on Embree's GitHub page (to learn more about Embree, visit their website).

  1. Install embree2 64-bit. If using vcpkg, this is done from the command-line as:
vcpkg install embree2:x64-windows

NOTE: To date, pyembree relies on Embree 2 and has not been updated version 3. The above command will install version 2.17.7, which is the required version.

  1. Create your project folder and initialize a virtual environment with venv. In this example, Python 3.8.5 x64-bit is chosen, simply as it is the Python version used in Miniconda py38_4.9.2. (It may work for Python 3.6 and 3.7, but at the time of this writing, one should not go to higher than 3.8)

  2. Install the following packages:

py -m pip install numpy cython wheel setuptools pyvista pykdtree rtree trimesh
  1. Navigate to <virtual environment folder>\Lib\site-packages and clone the pyembree repo:
git clone https://github.com/scopatz/pyembree.git

and remove the underlying .git subfolder.

  1. Move into pyembree folder and modify the setup.py file to:
import os
from setuptools import find_packages, setup

import numpy as np
from Cython.Build import cythonize
from Cython.Distutils import build_ext


include_path = [
    np.get_include(),
]

ext_modules = cythonize("pyembree/*.pyx", language_level=3, include_path=include_path)

for ext in ext_modules:
    ext.include_dirs = include_path
    ext.libraries = [
        "pyembree/embree2/lib/embree",
        "pyembree/embree2/lib/tbb",
        "pyembree/embree2/lib/tbbmalloc",
    ]

setup(
    name="pyembree",
    version="0.1.6",
    cmdclass={"build_ext": build_ext},
    ext_modules=ext_modules,
    zip_safe=False,
    packages=find_packages(),
    include_package_data=True,
    package_data={"pyembree": ["*.cpp", "*.dll"]},
)
  1. Move into the pyembree subfolder. Copy the folder C:\vcpkg\installed\x64-windows\include\embree2 into this folder (if you installed from the .msi, this will be the folder C:\Program Files\Intel\Embree v2.17.7 x64\include\embree2). In addition, copy the libraries from C:\vcpkg\installed\x64-windows\lib into this embree2 folder (if you installed from the .msi, this will be the folder C:\Program Files\Intel\Embree v2.17.7 x64\lib\). You only need the (static) libraries
embree.lib
tbb.lib
tbbmalloc.lib

and dynamic libraries

embree.dll
tbb.dll
tbbmalloc.dll
  1. Add the following line to the top of every *.pyx and *.pxd file in pyembree:
# distutils: language=c++

and change every relative import of an rtcore module to an absolute import in each file. For example, change:

cimport rtcore as rtc

to

cimport pyembree.rtcore as rtc
  1. Create the following MANIFEST.in file in the top-level pyembree folder:
include *.h *.pxd *.dll
recursive-include embree2 *.h *.isph
recursive-include embree2/lib *.lib
  1. At the end, your folder should look like this:
<virtual environment folder>\Lib\site-packages\pyembree
β”‚   .authors.yml
β”‚   .gitignore
β”‚   .mailmap
β”‚   .travis-install.sh
β”‚   .travis.yml
β”‚   AUTHORS
β”‚   CHANGELOG.rst
β”‚   LICENSE
β”‚   MANIFEST.in
β”‚   README.rst
β”‚   rever.xsh
β”‚   setup.py
β”‚   
β”œβ”€β”€β”€examples
β”‚       attenuate.py
β”‚       intersection.py
β”‚       
β”œβ”€β”€β”€news
β”‚       TEMPLATE.rst
β”‚       
β”œβ”€β”€β”€pyembree
β”‚   β”‚   embree.dll
β”‚   β”‚   mesh_construction.h
β”‚   β”‚   mesh_construction.pyx
β”‚   β”‚   rtcore.pxd
β”‚   β”‚   rtcore.pyx
β”‚   β”‚   rtcore_geometry.pxd
β”‚   β”‚   rtcore_geometry_user.pxd
β”‚   β”‚   rtcore_ray.pxd
β”‚   β”‚   rtcore_scene.pxd
β”‚   β”‚   rtcore_scene.pyx
β”‚   β”‚   tbb.dll
β”‚   β”‚   tbbmalloc.dll
β”‚   β”‚   triangles.pyx
β”‚   β”‚   __init__.pxd
β”‚   β”‚   __init__.py
β”‚   β”‚
β”‚   └───embree2
β”‚       β”‚   rtcore.h
β”‚       β”‚   rtcore.isph
β”‚       β”‚   rtcore_builder.h
β”‚       β”‚   rtcore_geometry.h
β”‚       β”‚   rtcore_geometry.isph
β”‚       β”‚   rtcore_geometry_user.h
β”‚       β”‚   rtcore_geometry_user.isph
β”‚       β”‚   rtcore_ray.h
β”‚       β”‚   rtcore_ray.isph
β”‚       β”‚   rtcore_scene.h
β”‚       β”‚   rtcore_scene.isph
β”‚       β”‚   rtcore_version.h
β”‚       β”‚
β”‚       └───lib
β”‚               embree.lib
β”‚               tbb.lib
β”‚               tbbmalloc.lib
β”‚
β”œβ”€β”€β”€recipes
β”‚   └───pyembree
β”‚           build.sh
β”‚           meta.yaml
β”‚
└───tests
        test_intersection.py
  1. Build pyembree by running the following from the top-level pyembree folder (TIP: To help debug errors, pipe stderr to a local file errors.txt that you can look at):
py setup.py build_ext -i 2> errors.txt
  1. Test that everything is working correctly by opening a python terminal in your virtual environment and running
>>> import pyembree
>>> from pyembree import rtcore_scene
>>>

If you get no errors, then pyembree has been installed correctly. You can also create a .egg and install the library with

py setup.py install

The setup.py we created will copy the dlls and cpp files to the correct folder.

  1. As an last optional step, create a main.py in your virtual environment and copy and paste the code from Project to Finite Plane. If it runs without errors in 1-2 seconds, then pyembree is working properly with trimesh for vectorized ray tracing (NOTE: trimesh will work without pyembree, but it will be very slow. It should not take a long time to run this example code if pyembree is properly installed. trimesh resorts back to trimesh.ray.ray_triangle.RayMeshIntersector if it cannot import pyembree (see pyembree ray casting acceleration #875), so you won't see any errors; just slow running code):
import numpy as np
from pykdtree.kdtree import KDTree

import pyvista as pv
from pyvista import examples

# Load data
data = examples.load_random_hills()
data.translate((10, 10, 10))

# Create triangular plane (vertices [10, 0, 0], [0, 10, 0], [0, 0, 10])
size = 10
vertices = np.array([[size, 0, 0], [0, size, 0], [0, 0, size]])
face = np.array([3, 0, 1, 2])

planes = pv.PolyData(vertices, face)

# Subdivide plane so we have multiple points to project to
planes = planes.subdivide(8)

# Get origins and normals
origins = planes.cell_centers().points
normals = planes.compute_normals(cell_normals=True, point_normals=False)["Normals"]

# Vectorized Ray trace
points, pt_inds, cell_inds = data.multi_ray_trace(
    origins, normals
)  # Must have rtree, trimesh, and pyembree installed

# Filter based on distance threshold, if desired (mimics VTK ray_trace behavior)
# threshold = 10  # Some threshold distance
# distances = np.linalg.norm(origins[inds] - points, ord=2, axis=1)
# inds = inds[distances <= threshold]

tree = KDTree(data.points.astype(np.double))
_, data_inds = tree.query(points)

elevations = data.point_arrays["Elevation"][data_inds]

# Mask points on planes
planes.cell_arrays["Elevation"] = np.zeros((planes.n_cells,))
planes.cell_arrays["Elevation"][pt_inds] = elevations
planes.set_active_scalars("Elevation")  # Probably not necessary, but just in case

# Create axes
axis_length = 20
tip_length = 0.25 / axis_length * 3
tip_radius = 0.1 / axis_length * 3
shaft_radius = 0.05 / axis_length * 3
x_axis = pv.Arrow(
    direction=(axis_length, 0, 0),
    tip_length=tip_length,
    tip_radius=tip_radius,
    shaft_radius=shaft_radius,
    scale="auto",
)
y_axis = pv.Arrow(
    direction=(0, axis_length, 0),
    tip_length=tip_length,
    tip_radius=tip_radius,
    shaft_radius=shaft_radius,
    scale="auto",
)
z_axis = pv.Arrow(
    direction=(0, 0, axis_length),
    tip_length=tip_length,
    tip_radius=tip_radius,
    shaft_radius=shaft_radius,
    scale="auto",
)
x_label = pv.PolyData([axis_length, 0, 0])
y_label = pv.PolyData([0, axis_length, 0])
z_label = pv.PolyData([0, 0, axis_length])
x_label.point_arrays["label"] = [
    "x",
]
y_label.point_arrays["label"] = [
    "y",
]
z_label.point_arrays["label"] = [
    "z",
]

# Plot results
p = pv.Plotter()
p.add_mesh(x_axis, color="r")
p.add_point_labels(x_label, "label", show_points=False, font_size=24)
p.add_mesh(y_axis, color="r")
p.add_point_labels(y_label, "label", show_points=False, font_size=24)
p.add_mesh(z_axis, color="r")
p.add_point_labels(z_label, "label", show_points=False, font_size=24)
p.add_mesh(data)
p.add_mesh(planes)
p.show()

It would probably be best to put in a PR to the pyembree-feedstock for building on windows

I've opened a feature request on the pyembree-feedstock here

Installation Instructions

Tested on:

OS: Windows 10 x64 Professional, Build 1909
Python: 3.8.5 x64
Date: 31-JULY-2021

Steps

  1. Install Microsoft Visual Studio 2017 Build Tools and the Windows 10 SDK. These are required for building cython code.

(NOTE: FYI, Microsoft Visual Studio version numbers are not the same as Microsoft Visual C++ Compiler versions. MSVCv14X x64/x86 build tools are required for Python 3.8. Installing the Visual Studio 2017 Build Tools with the Windows 10 SDK. If you wish to install Visual Studio 2017, select the Desktop development with C++ Workload and make sure the required Windows 10 SDK build tool is selected under Individual Components. Refer to the Python Wiki for the right build tool versions to install).

  1. Install vcpkg in C:\vcpkg and add the path to your System Environment Variables. Be sure to bootstrap and integrate vcpkg:
cd C:\vcpkg
git clone https://github.com/Microsoft/vcpkg.git
bootstrap-vcpkg.bat
vcpkg integrate install

Alternatively, you can download and install the embree-2.17.7.x64.msi Installer on Embree's GitHub page (to learn more about Embree, visit their website).

  1. Install embree2 64-bit. If using vcpkg, this is done from the command-line as:
vcpkg install embree2:x64-windows

NOTE: To date, pyembree relies on Embree 2 and has not been updated version 3. The above command will install version 2.17.7, which is the required version.

  1. Create your project folder and initialize a virtual environment with venv. In this example, Python 3.8.5 x64-bit is chosen, simply as it is the Python version used in Miniconda py38_4.9.2. (It may work for Python 3.6 and 3.7, but at the time of this writing, one should not go to higher than 3.8)
  2. Install the following packages:
py -m pip install numpy cython wheel setuptools pyvista pykdtree rtree trimesh
  1. Navigate to <virtual environment folder>\Lib\site-packages and clone the pyembree repo:
git clone https://github.com/scopatz/pyembree.git

and remove the underlying .git subfolder.

  1. Move into pyembree folder and modify the setup.py file to:
import os
from setuptools import find_packages, setup

import numpy as np
from Cython.Build import cythonize
from Cython.Distutils import build_ext


include_path = [
    np.get_include(),
]

ext_modules = cythonize("pyembree/*.pyx", language_level=3, include_path=include_path)

for ext in ext_modules:
    ext.include_dirs = include_path
    ext.libraries = [
        "pyembree/embree2/lib/embree",
        "pyembree/embree2/lib/tbb",
        "pyembree/embree2/lib/tbbmalloc",
    ]

setup(
    name="pyembree",
    version="0.1.6",
    cmdclass={"build_ext": build_ext},
    ext_modules=ext_modules,
    zip_safe=False,
    packages=find_packages(),
    include_package_data=True,
    package_data={"pyembree": ["*.cpp", "*.dll"]},
)
  1. Move into the pyembree subfolder. Copy the folder C:\vcpkg\installed\x64-windows\include\embree2 into this folder (if you installed from the .msi, this will be the folder C:\Program Files\Intel\Embree v2.17.7 x64\include\embree2). In addition, copy the libraries from C:\vcpkg\installed\x64-windows\lib into this embree2 folder (if you installed from the .msi, this will be the folder C:\Program Files\Intel\Embree v2.17.7 x64\lib\). You only need the (static) libraries
embree.lib
tbb.lib
tbbmalloc.lib

and dynamic libraries

embree.dll
tbb.dll
tbbmalloc.dll
  1. Add the following line to the top of every *.pyx and *.pxd file in pyembree:
# distutils: language=c++

and change every relative import of an rtcore module to an absolute import in each file. For example, change:

cimport rtcore as rtc

to

cimport pyembree.rtcore as rtc
  1. Create the following MANIFEST.in file in the top-level pyembree folder:
include *.h *.pxd *.dll
recursive-include embree2 *.h *.isph
recursive-include embree2/lib *.lib
  1. At the end, your folder should look like this:
<virtual environment folder>\Lib\site-packages\pyembree
β”‚   .authors.yml
β”‚   .gitignore
β”‚   .mailmap
β”‚   .travis-install.sh
β”‚   .travis.yml
β”‚   AUTHORS
β”‚   CHANGELOG.rst
β”‚   LICENSE
β”‚   MANIFEST.in
β”‚   README.rst
β”‚   rever.xsh
β”‚   setup.py
β”‚   
β”œβ”€β”€β”€examples
β”‚       attenuate.py
β”‚       intersection.py
β”‚       
β”œβ”€β”€β”€news
β”‚       TEMPLATE.rst
β”‚       
β”œβ”€β”€β”€pyembree
β”‚   β”‚   embree.dll
β”‚   β”‚   mesh_construction.h
β”‚   β”‚   mesh_construction.pyx
β”‚   β”‚   rtcore.pxd
β”‚   β”‚   rtcore.pyx
β”‚   β”‚   rtcore_geometry.pxd
β”‚   β”‚   rtcore_geometry_user.pxd
β”‚   β”‚   rtcore_ray.pxd
β”‚   β”‚   rtcore_scene.pxd
β”‚   β”‚   rtcore_scene.pyx
β”‚   β”‚   tbb.dll
β”‚   β”‚   tbbmalloc.dll
β”‚   β”‚   triangles.pyx
β”‚   β”‚   __init__.pxd
β”‚   β”‚   __init__.py
β”‚   β”‚
β”‚   └───embree2
β”‚       β”‚   rtcore.h
β”‚       β”‚   rtcore.isph
β”‚       β”‚   rtcore_builder.h
β”‚       β”‚   rtcore_geometry.h
β”‚       β”‚   rtcore_geometry.isph
β”‚       β”‚   rtcore_geometry_user.h
β”‚       β”‚   rtcore_geometry_user.isph
β”‚       β”‚   rtcore_ray.h
β”‚       β”‚   rtcore_ray.isph
β”‚       β”‚   rtcore_scene.h
β”‚       β”‚   rtcore_scene.isph
β”‚       β”‚   rtcore_version.h
β”‚       β”‚
β”‚       └───lib
β”‚               embree.lib
β”‚               tbb.lib
β”‚               tbbmalloc.lib
β”‚
β”œβ”€β”€β”€recipes
β”‚   └───pyembree
β”‚           build.sh
β”‚           meta.yaml
β”‚
└───tests
        test_intersection.py
  1. Build pyembree by running the following from the top-level pyembree folder (TIP: To help debug errors, pipe stderr to a local file errors.txt that you can look at):
py setup.py build_ext -i 2> errors.txt
  1. Test that everything is working correctly by opening a python terminal in your virtual environment and running
>>> import pyembree
>>> from pyembree import rtcore_scene
>>>

If you get no errors, then pyembree has been installed correctly. You can also create a .egg and install the library with

py setup.py install

The setup.py we created will copy the dlls and cpp files to the correct folder.

  1. As an last optional step, create a main.py in your virtual environment and copy and paste the code from Project to Finite Plane. If it runs without errors in 1-2 seconds, then pyembree is working properly with trimesh for vectorized ray tracing (NOTE: trimesh will work without pyembree, but it will be very slow. It should not take a long time to run this example code if pyembree is properly installed. trimesh resorts back to trimesh.ray.ray_triangle.RayMeshIntersector if it cannot import pyembree (see pyembree ray casting acceleration #875), so you won't see any errors; just slow running code):
import numpy as np
from pykdtree.kdtree import KDTree

import pyvista as pv
from pyvista import examples

# Load data
data = examples.load_random_hills()
data.translate((10, 10, 10))

# Create triangular plane (vertices [10, 0, 0], [0, 10, 0], [0, 0, 10])
size = 10
vertices = np.array([[size, 0, 0], [0, size, 0], [0, 0, size]])
face = np.array([3, 0, 1, 2])

planes = pv.PolyData(vertices, face)

# Subdivide plane so we have multiple points to project to
planes = planes.subdivide(8)

# Get origins and normals
origins = planes.cell_centers().points
normals = planes.compute_normals(cell_normals=True, point_normals=False)["Normals"]

# Vectorized Ray trace
points, pt_inds, cell_inds = data.multi_ray_trace(
    origins, normals
)  # Must have rtree, trimesh, and pyembree installed

# Filter based on distance threshold, if desired (mimics VTK ray_trace behavior)
# threshold = 10  # Some threshold distance
# distances = np.linalg.norm(origins[inds] - points, ord=2, axis=1)
# inds = inds[distances <= threshold]

tree = KDTree(data.points.astype(np.double))
_, data_inds = tree.query(points)

elevations = data.point_arrays["Elevation"][data_inds]

# Mask points on planes
planes.cell_arrays["Elevation"] = np.zeros((planes.n_cells,))
planes.cell_arrays["Elevation"][pt_inds] = elevations
planes.set_active_scalars("Elevation")  # Probably not necessary, but just in case

# Create axes
axis_length = 20
tip_length = 0.25 / axis_length * 3
tip_radius = 0.1 / axis_length * 3
shaft_radius = 0.05 / axis_length * 3
x_axis = pv.Arrow(
    direction=(axis_length, 0, 0),
    tip_length=tip_length,
    tip_radius=tip_radius,
    shaft_radius=shaft_radius,
    scale="auto",
)
y_axis = pv.Arrow(
    direction=(0, axis_length, 0),
    tip_length=tip_length,
    tip_radius=tip_radius,
    shaft_radius=shaft_radius,
    scale="auto",
)
z_axis = pv.Arrow(
    direction=(0, 0, axis_length),
    tip_length=tip_length,
    tip_radius=tip_radius,
    shaft_radius=shaft_radius,
    scale="auto",
)
x_label = pv.PolyData([axis_length, 0, 0])
y_label = pv.PolyData([0, axis_length, 0])
z_label = pv.PolyData([0, 0, axis_length])
x_label.point_arrays["label"] = [
    "x",
]
y_label.point_arrays["label"] = [
    "y",
]
z_label.point_arrays["label"] = [
    "z",
]

# Plot results
p = pv.Plotter()
p.add_mesh(x_axis, color="r")
p.add_point_labels(x_label, "label", show_points=False, font_size=24)
p.add_mesh(y_axis, color="r")
p.add_point_labels(y_label, "label", show_points=False, font_size=24)
p.add_mesh(z_axis, color="r")
p.add_point_labels(z_label, "label", show_points=False, font_size=24)
p.add_mesh(data)
p.add_mesh(planes)
p.show()

Blood, sweat, and tears.

I did:

git clone https://github.com/scopatz/pyembree.git
cd pyembree
conda install cython numpy
conda install -c conda-forge embree
set INCLUDE=%CONDA_PREFIX%\Library\include
set LIB=%CONDA_PREFIX%\Library\lib
python setup.py install --prefix=%CONDA_PREFIX%

I got error when import rtcore_scene

from pyembree import rtcore_scene

error message:

Traceback (most recent call last):
  File "D:\Github\package_solutions\Solution\CheckRibHeight_ver2\main.py", line 3, in <module>
    from pyembree import rtcore_scene
ImportError: DLL load failed while importing rtcore_scene: The specified module could not be found.

Environment: Conda, python3.9

@maycuatroi and @vinnik-dmitry07

Follow the instructions at the end of the post here on pyvista. These instructions are for Windows users to install without conda as pyembree only supports Mac and Linux via conda forge.

I did:

git clone https://github.com/scopatz/pyembree.git
cd pyembree
conda install cython numpy
conda install -c conda-forge embree
set INCLUDE=%CONDA_PREFIX%\Library\include
set LIB=%CONDA_PREFIX%\Library\lib
python setup.py install --prefix=%CONDA_PREFIX%

I got error when import rtcore_scene

from pyembree import rtcore_scene

error message:

Traceback (most recent call last):
  File "D:\Github\package_solutions\Solution\CheckRibHeight_ver2\main.py", line 3, in <module>
    from pyembree import rtcore_scene
ImportError: DLL load failed while importing rtcore_scene: The specified module could not be found.

Environment: Conda, python3.9

That won't work. Follow the instructions I made that @vinnik-dmitry07 has shown.

For what it's worth it's quite easy to install by hand on Windows 10. The following steps work for me with Anaconda:

  • git clone https://github.com/scopatz/pyembree.git
  • cd pyembree
  • conda install cython numpy
  • conda install -c conda-forge embree
  • set INCLUDE=%CONDA_PREFIX%\Library\include
  • set LIB=%CONDA_PREFIX%\Library\lib
  • python setup.py install --prefix=%CONDA_PREFIX%

this works for me nicely, thank you!

For what it's worth it's quite easy to install by hand on Windows 10. The following steps work for me with Anaconda:

  • git clone https://github.com/scopatz/pyembree.git
  • cd pyembree
  • conda install cython numpy
  • conda install -c conda-forge embree
  • set INCLUDE=%CONDA_PREFIX%\Library\include
  • set LIB=%CONDA_PREFIX%\Library\lib
  • python setup.py install --prefix=%CONDA_PREFIX%

this works for me nicely, thank you!

  1. Anaconda has a restrictive license for business applications. You must pay them if you are going to use Anaconda, which is the biggest restriction to using Anaconda.

  2. Many Anaconda libraries are not the latest version and not all libraries are on Anaconda, but rather through PyPI.

  3. Dependency management tools like poetry still do not work well with Anaconda.

I don't recommend Anaconda, nor jupyter notebooks. While useful for personal use/teaching applications where the required libraries need static/shared lib's or DLL's, it's not conducive to building and distributing professional-level applications.

Wherever possible, build the source yourself so you're not handcuffed to a 3rd-party vendor.

Installation Instructions

Tested on:

OS: Windows 10 x64 Professional, Build 1909 Python: 3.8.5 x64 Date: 31-JULY-2021

Steps

  1. Install Microsoft Visual Studio 2017 Build Tools and the Windows 10 SDK. These are required for building cython code.

(NOTE: FYI, Microsoft Visual Studio version numbers are not the same as Microsoft Visual C++ Compiler versions. MSVCv14X x64/x86 build tools are required for Python 3.8. Installing the Visual Studio 2017 Build Tools with the Windows 10 SDK. If you wish to install Visual Studio 2017, select the Desktop development with C++ Workload and make sure the required Windows 10 SDK build tool is selected under Individual Components. Refer to the Python Wiki for the right build tool versions to install).

  1. Install vcpkg in C:\vcpkg and add the path to your System Environment Variables. Be sure to bootstrap and integrate vcpkg:
cd C:\vcpkg
git clone https://github.com/Microsoft/vcpkg.git
bootstrap-vcpkg.bat
vcpkg integrate install

Alternatively, you can download and install the embree-2.17.7.x64.msi Installer on Embree's GitHub page (to learn more about Embree, visit their website).

  1. Install embree2 64-bit. If using vcpkg, this is done from the command-line as:
vcpkg install embree2:x64-windows

NOTE: To date, pyembree relies on Embree 2 and has not been updated version 3. The above command will install version 2.17.7, which is the required version.

  1. Create your project folder and initialize a virtual environment with venv. In this example, Python 3.8.5 x64-bit is chosen, simply as it is the Python version used in Miniconda py38_4.9.2. (It may work for Python 3.6 and 3.7, but at the time of this writing, one should not go to higher than 3.8)
  2. Install the following packages:
py -m pip install numpy cython wheel setuptools pyvista pykdtree rtree trimesh
  1. Navigate to <virtual environment folder>\Lib\site-packages and clone the pyembree repo:
git clone https://github.com/scopatz/pyembree.git

and remove the underlying .git subfolder.

  1. Move into pyembree folder and modify the setup.py file to:
import os
from setuptools import find_packages, setup

import numpy as np
from Cython.Build import cythonize
from Cython.Distutils import build_ext


include_path = [
    np.get_include(),
]

ext_modules = cythonize("pyembree/*.pyx", language_level=3, include_path=include_path)

for ext in ext_modules:
    ext.include_dirs = include_path
    ext.libraries = [
        "pyembree/embree2/lib/embree",
        "pyembree/embree2/lib/tbb",
        "pyembree/embree2/lib/tbbmalloc",
    ]

setup(
    name="pyembree",
    version="0.1.6",
    cmdclass={"build_ext": build_ext},
    ext_modules=ext_modules,
    zip_safe=False,
    packages=find_packages(),
    include_package_data=True,
    package_data={"pyembree": ["*.cpp", "*.dll"]},
)
  1. Move into the pyembree subfolder. Copy the folder C:\vcpkg\installed\x64-windows\include\embree2 into this folder (if you installed from the .msi, this will be the folder C:\Program Files\Intel\Embree v2.17.7 x64\include\embree2). In addition, copy the libraries from C:\vcpkg\installed\x64-windows\lib into this embree2 folder (if you installed from the .msi, this will be the folder C:\Program Files\Intel\Embree v2.17.7 x64\lib\). You only need the (static) libraries
embree.lib
tbb.lib
tbbmalloc.lib

and dynamic libraries

embree.dll
tbb.dll
tbbmalloc.dll
  1. Add the following line to the top of every *.pyx and *.pxd file in pyembree:
# distutils: language=c++

and change every relative import of an rtcore module to an absolute import in each file. For example, change:

cimport rtcore as rtc

to

cimport pyembree.rtcore as rtc
  1. Create the following MANIFEST.in file in the top-level pyembree folder:
include *.h *.pxd *.dll
recursive-include embree2 *.h *.isph
recursive-include embree2/lib *.lib
  1. At the end, your folder should look like this:
<virtual environment folder>\Lib\site-packages\pyembree
β”‚   .authors.yml
β”‚   .gitignore
β”‚   .mailmap
β”‚   .travis-install.sh
β”‚   .travis.yml
β”‚   AUTHORS
β”‚   CHANGELOG.rst
β”‚   LICENSE
β”‚   MANIFEST.in
β”‚   README.rst
β”‚   rever.xsh
β”‚   setup.py
β”‚   
β”œβ”€β”€β”€examples
β”‚       attenuate.py
β”‚       intersection.py
β”‚       
β”œβ”€β”€β”€news
β”‚       TEMPLATE.rst
β”‚       
β”œβ”€β”€β”€pyembree
β”‚   β”‚   embree.dll
β”‚   β”‚   mesh_construction.h
β”‚   β”‚   mesh_construction.pyx
β”‚   β”‚   rtcore.pxd
β”‚   β”‚   rtcore.pyx
β”‚   β”‚   rtcore_geometry.pxd
β”‚   β”‚   rtcore_geometry_user.pxd
β”‚   β”‚   rtcore_ray.pxd
β”‚   β”‚   rtcore_scene.pxd
β”‚   β”‚   rtcore_scene.pyx
β”‚   β”‚   tbb.dll
β”‚   β”‚   tbbmalloc.dll
β”‚   β”‚   triangles.pyx
β”‚   β”‚   __init__.pxd
β”‚   β”‚   __init__.py
β”‚   β”‚
β”‚   └───embree2
β”‚       β”‚   rtcore.h
β”‚       β”‚   rtcore.isph
β”‚       β”‚   rtcore_builder.h
β”‚       β”‚   rtcore_geometry.h
β”‚       β”‚   rtcore_geometry.isph
β”‚       β”‚   rtcore_geometry_user.h
β”‚       β”‚   rtcore_geometry_user.isph
β”‚       β”‚   rtcore_ray.h
β”‚       β”‚   rtcore_ray.isph
β”‚       β”‚   rtcore_scene.h
β”‚       β”‚   rtcore_scene.isph
β”‚       β”‚   rtcore_version.h
β”‚       β”‚
β”‚       └───lib
β”‚               embree.lib
β”‚               tbb.lib
β”‚               tbbmalloc.lib
β”‚
β”œβ”€β”€β”€recipes
β”‚   └───pyembree
β”‚           build.sh
β”‚           meta.yaml
β”‚
└───tests
        test_intersection.py
  1. Build pyembree by running the following from the top-level pyembree folder (TIP: To help debug errors, pipe stderr to a local file errors.txt that you can look at):
py setup.py build_ext -i 2> errors.txt
  1. Test that everything is working correctly by opening a python terminal in your virtual environment and running
>>> import pyembree
>>> from pyembree import rtcore_scene
>>>

If you get no errors, then pyembree has been installed correctly. You can also create a .egg and install the library with

py setup.py install

The setup.py we created will copy the dlls and cpp files to the correct folder.

  1. As an last optional step, create a main.py in your virtual environment and copy and paste the code from Project to Finite Plane. If it runs without errors in 1-2 seconds, then pyembree is working properly with trimesh for vectorized ray tracing (NOTE: trimesh will work without pyembree, but it will be very slow. It should not take a long time to run this example code if pyembree is properly installed. trimesh resorts back to trimesh.ray.ray_triangle.RayMeshIntersector if it cannot import pyembree (see pyembree ray casting acceleration #875), so you won't see any errors; just slow running code):
import numpy as np
from pykdtree.kdtree import KDTree

import pyvista as pv
from pyvista import examples

# Load data
data = examples.load_random_hills()
data.translate((10, 10, 10))

# Create triangular plane (vertices [10, 0, 0], [0, 10, 0], [0, 0, 10])
size = 10
vertices = np.array([[size, 0, 0], [0, size, 0], [0, 0, size]])
face = np.array([3, 0, 1, 2])

planes = pv.PolyData(vertices, face)

# Subdivide plane so we have multiple points to project to
planes = planes.subdivide(8)

# Get origins and normals
origins = planes.cell_centers().points
normals = planes.compute_normals(cell_normals=True, point_normals=False)["Normals"]

# Vectorized Ray trace
points, pt_inds, cell_inds = data.multi_ray_trace(
    origins, normals
)  # Must have rtree, trimesh, and pyembree installed

# Filter based on distance threshold, if desired (mimics VTK ray_trace behavior)
# threshold = 10  # Some threshold distance
# distances = np.linalg.norm(origins[inds] - points, ord=2, axis=1)
# inds = inds[distances <= threshold]

tree = KDTree(data.points.astype(np.double))
_, data_inds = tree.query(points)

elevations = data.point_arrays["Elevation"][data_inds]

# Mask points on planes
planes.cell_arrays["Elevation"] = np.zeros((planes.n_cells,))
planes.cell_arrays["Elevation"][pt_inds] = elevations
planes.set_active_scalars("Elevation")  # Probably not necessary, but just in case

# Create axes
axis_length = 20
tip_length = 0.25 / axis_length * 3
tip_radius = 0.1 / axis_length * 3
shaft_radius = 0.05 / axis_length * 3
x_axis = pv.Arrow(
    direction=(axis_length, 0, 0),
    tip_length=tip_length,
    tip_radius=tip_radius,
    shaft_radius=shaft_radius,
    scale="auto",
)
y_axis = pv.Arrow(
    direction=(0, axis_length, 0),
    tip_length=tip_length,
    tip_radius=tip_radius,
    shaft_radius=shaft_radius,
    scale="auto",
)
z_axis = pv.Arrow(
    direction=(0, 0, axis_length),
    tip_length=tip_length,
    tip_radius=tip_radius,
    shaft_radius=shaft_radius,
    scale="auto",
)
x_label = pv.PolyData([axis_length, 0, 0])
y_label = pv.PolyData([0, axis_length, 0])
z_label = pv.PolyData([0, 0, axis_length])
x_label.point_arrays["label"] = [
    "x",
]
y_label.point_arrays["label"] = [
    "y",
]
z_label.point_arrays["label"] = [
    "z",
]

# Plot results
p = pv.Plotter()
p.add_mesh(x_axis, color="r")
p.add_point_labels(x_label, "label", show_points=False, font_size=24)
p.add_mesh(y_axis, color="r")
p.add_point_labels(y_label, "label", show_points=False, font_size=24)
p.add_mesh(z_axis, color="r")
p.add_point_labels(z_label, "label", show_points=False, font_size=24)
p.add_mesh(data)
p.add_mesh(planes)
p.show()

Note in step 7 above that setuptools MUST be imported before Cython.Build.cythonize.

setuptools overrides the Extension class from distutils , so when build_ext checks the Extension list, isinstance will fail and you'll get the error message

each element of 'ext_modules' option must be an Extension instance or 2-tuple

Unfortunately (sort of), if you use isort, flake8, or another code formatter, it will put Cython ahead of setuptools. PEP 8 doesn't require imports be sorted alphabetically, but these tools do it for ease of readability. Be careful when checking in code that your formatter doesn't mess the order up.

Instead of turning code formatting off, you can do one of 2 things:

  1. Add import setuptools in addition to the from ... imports. Since PEP 8 import grouping is:

Imports should be grouped in the following order:

Standard library imports.
Related third party imports.
Local application/library specific imports.

from ... import ...s happen last (within any group) because they put all they count as local imports (making all names in that module available in the local namespace).

This solution assumes your sorter won't change in the future, but also that you are only importing from Cython with from ... import ...s.

  1. Re-monkey patch the distutils.extension.Extension class
from distutils.extension import Extension as _Extension
from setuptools import setup 
distutils.extension.Extension = _Extension
distutils.command.build_ext.Extension = _Extension
Extension = _Extension
from Cython.Distutils import build_ext 

However, I don't think this is very bullet-proof.

I've opened an issue with Cython to see if they can address this:

[BUG] check_extensions_lists Fails isinstance Check Depending on Import Order #4724

For those interested, I've created a fork of this repo where I've implemented these fixes and added the required DLLs:

https://github.com/adam-grant-hendry/pyembree

It's not pip installable, but you should be able to clone the repo and build from source directly with

> py setup.py build_ext -i

The only prerequisite (besides an Intel CPU) is that you have the Visual Studio Build Tools.

Alternatively, I've placed the Windows Python 3.8 *.pyd binary files in the Releases. Simply copy and paste those into the cloned pyembree folder (alongside the *.pyx files), and it should run for Windows users on Python 3.8.

You can know pip install my fork of pyembree. (see PyPI link here)

For what it's worth it's quite easy to install by hand on Windows 10. The following steps work for me with Anaconda:

  • git clone https://github.com/scopatz/pyembree.git
  • cd pyembree
  • conda install cython numpy
  • conda install -c conda-forge embree
  • set INCLUDE=%CONDA_PREFIX%\Library\include
  • set LIB=%CONDA_PREFIX%\Library\lib
  • python setup.py install --prefix=%CONDA_PREFIX%

Useful!
thx u so much

You can know pip install my fork of pyembree. (see PyPI link here)

Kind of works, but if I for example do from pyembree import rtcore_scene as Trimesh would, it gives me a cannot import name 'rtcore_scene' from 'pyembree'.. maybe this has more recently broken?

You can know pip install my fork of pyembree. (see PyPI link here)

Kind of works, but if I for example do from pyembree import rtcore_scene as Trimesh would, it gives me a cannot import name 'rtcore_scene' from 'pyembree'.. maybe this has more recently broken?

I got it to install by:

  1. installing embree 2.17.7 using the .msi, creating a python 3.9.16 environment

  2. cloning pbsds's fork into site packages https://github.com/pbsds/pyembree/tree/python-bump

  3. copying the embree installation into the pyembree subfolder and renaming it embree

  4. running python setup.py build_ext -i 2> errors.txt

  5. installing it with pip using the --ignore-requires-python option. (so it doesn't get hung up on me having 3.9.16 rather than 3.9.0)

There unfortunately no longer seems to be an embree2 package available in vcpkg. I appreciate the work maintaining pyembree, I never would have got it to install without that work!

Hey all, my apologies. I've been MIA for nearly 4 months on several other work projects. I've been wanting to upgrade this fork to add Python 3.9-3.11 (if possible) and also to add embree3. I've just been swamped with the day job. Someone's already opened up a PR to add support for Python other than 3.8, but some tests were failing. I wanted to revamp that. I might just go ahead and make a separate package altogether that supports embree 2 and 3, but just give it a different name. Again, all things I desperately want to do, I've just completely run out of time (even to look at other's PRs). Thanks in advance for your patience.

Noted here that I could not get 'from pyembree import rtcore_scene' to successfully pass in a Miniconda environment running Python 3.8.10. (I used the pip install pyembree as suggested). I get:

ImportError: DLL load failed while importing rtcore_scene: The specified module could not be found.

I did get it to work using iPython as well as a python distribution from a native 3.8.10. (https://www.python.org/downloads/release/python-3810/)

Any idea why Miniconda fails? I am in a Windows 10 Env.

For what it's worth it's quite easy to install by hand on Windows 10. The following steps work for me with Anaconda:

  • git clone https://github.com/scopatz/pyembree.git
  • cd pyembree
  • conda install cython numpy
  • conda install -c conda-forge embree
  • set INCLUDE=%CONDA_PREFIX%\Library\include
  • set LIB=%CONDA_PREFIX%\Library\lib
  • python setup.py install --prefix=%CONDA_PREFIX%

For this method, I found that this works with specific versions of libraries.
In my experience, it worked with cython 0.29.33 and embree 2.14.0 on python 3.8.