3

Edit: For those interested, the creator is currently working on this here.

I am trying to install pygalmesh using pip install pygalmesh, which depends on Eigen. I have downloaded Eigen, but the pip installer does not "know" this. It returns the following error message:

ERROR: Could not build wheels for pygalmesh which use PEP 517 and cannot be installed directly

more specifically:

fatal error C1083: Cannot open include file: 'Eigen/Dense':

Pygalmesh's github has a file for setup.py which I could edit, but I don't know how I would then install pygalmesh. Still with pip?

Is there a setup.py file I can edit so that the installer knows where Eigen/Dense is located? Since I have a Windows PC, I at least think the / needs to be changed to \. But I cannot find a setup.py to edit.

I've found conversations about this problem elsewhere on the web, also here. I don't know how to implement what is talked about in these posts. I have also tried installing eigen through conda, like here. This also has not worked.

Error message in full:

Collecting pygalmesh
  Using cached pygalmesh-0.6.2.tar.gz (1.2 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
    Preparing wheel metadata ... done
Collecting pybind11>=2.2
  Using cached pybind11-2.5.0.tar.gz (139 kB)
Collecting meshio<5.0.0,>=4.0.0
  Downloading meshio-4.0.11.tar.gz (302 kB)
     |████████████████████████████████| 302 kB 2.2 MB/s
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: importlib-metadata in c:\users\user\anaconda3\lib\site-packages (from pygalmesh) (1.5.0)
Requirement already satisfied: numpy in c:\users\user\anaconda3\lib\site-packages (from pygalmesh) (1.16.2)
Requirement already satisfied: zipp>=0.5 in c:\users\user\anaconda3\lib\site-packages (from importlib-metadata->pygalmesh) (2.2.0)
Skipping wheel build for pybind11, due to binaries being disabled for it.
Building wheels for collected packages: pygalmesh, meshio
  Building wheel for pygalmesh (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\User\Anaconda3\python.exe' 'C:\Users\User\Anaconda3\lib\site-packages\pip\_vendor\pep517\_in_process.py' build_wheel 'C:\Users\User\AppData\Local\Temp\tmpa0eqknmo'
       cwd: C:\Users\User\AppData\Local\Temp\pip-install-qm6jy0mx\pygalmesh
  Complete output (24 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.7
  creating build\lib.win-amd64-3.7\pygalmesh
  copying pygalmesh\main.py -> build\lib.win-amd64-3.7\pygalmesh
  copying pygalmesh\__about__.py -> build\lib.win-amd64-3.7\pygalmesh
  copying pygalmesh\__init__.py -> build\lib.win-amd64-3.7\pygalmesh
  creating build\lib.win-amd64-3.7\pygalmesh\_cli
  copying pygalmesh\_cli\helpers.py -> build\lib.win-amd64-3.7\pygalmesh\_cli
  copying pygalmesh\_cli\_inr.py -> build\lib.win-amd64-3.7\pygalmesh\_cli
  copying pygalmesh\_cli\_remesh_surface.py -> build\lib.win-amd64-3.7\pygalmesh\_cli
  copying pygalmesh\_cli\_volume_from_surface.py -> build\lib.win-amd64-3.7\pygalmesh\_cli
  copying pygalmesh\_cli\__init__.py -> build\lib.win-amd64-3.7\pygalmesh\_cli
  running build_ext
  building '_pygalmesh' extension
  creating build\temp.win-amd64-3.7
  creating build\temp.win-amd64-3.7\Release
  creating build\temp.win-amd64-3.7\Release\src
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I/usr/include/eigen3/ -IC:\Users\User\AppData\Local\Temp\pip-build-env-bi2kt8ry\normal\Lib\site-packages\pybind11\include -IC:\Users\User\AppData\Local\Temp\pip-build-env-bi2kt8ry\normal\Lib\site-packages\pybind11\include -IC:\Users\User\Anaconda3\include -IC:\Users\User\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.7.2\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" /EHsc /Tpsrc/generate.cpp /Fobuild\temp.win-amd64-3.7\Release\src/generate.obj
  generate.cpp
  C:\Users\User\AppData\Local\Temp\pip-install-qm6jy0mx\pygalmesh\src\domain.hpp(4): fatal error C1083: Cannot open include file: 'Eigen/Dense': No such file or directory
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.22.27905\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
  ----------------------------------------
  ERROR: Failed building wheel for pygalmesh
  Building wheel for meshio (PEP 517) ... done
  Created wheel for meshio: filename=meshio-4.0.11-py3-none-any.whl size=127526 sha256=cc63c5792c3d20bce3532742afcccc100bc6312c1254e029f8771f286a5979c2
  Stored in directory: c:\users\user\appdata\local\pip\cache\wheels\17\27\cf\b034bc0b8bffd85475dfbab9791fcdeea89c77f040c4537afe
Successfully built meshio
Failed to build pygalmesh
ERROR: Could not build wheels for pygalmesh which use PEP 517 and cannot be installed directly

McM
  • 471
  • 5
  • 21
  • Is there any more verbose error message, or log? What is the version of _pip_, is it up to date? – sinoroc Apr 28 '20 at 06:37
  • Sure thing. Edited. And yes, _pip_ is up to date. – McM Apr 28 '20 at 12:08
  • Your actual issue seems to be this: `C:\Users\User\AppData\Local\Temp\pip-install-qm6jy0mx\pygalmesh\src\domain.hpp(4): fatal error C1083: Cannot open include file: 'Eigen/Dense': No such file or directory`. Getting this fixed should probably get you at least one step further. – sinoroc Apr 28 '20 at 12:17
  • Okay.. I saw that. So I should download that separately. It's weird, there actually isn't a folder ```C:\Users\User\AppData\Local\Temp\pip-install-qm6jy0mx\```. When I download it, where do I put it? Thanks! – McM Apr 28 '20 at 14:24
  • I don't know the details, but according to [_pygalmesh_ installation instructions](https://github.com/nschloe/pygalmesh#installation), there is a dependency on something called [_Eigen_](http://eigen.tuxfamily.org/index.php?title=Main_Page), that you most likely need to somehow make available to the compiler before-hand. – sinoroc Apr 28 '20 at 14:49
  • Ahhh, ok. I couldn't find the directions. Thank you! I'm not sure how I will 'make it available to the compiler'. I'm running on Windows, so I don't know if that will complicate things either! – McM Apr 28 '20 at 14:54
  • I'm sorry, I was busy and didn't read this website correctly. I don't see how this will help with installing something using conda. Do you? – McM Apr 30 '20 at 22:24
  • My post is not resolved. Would it be okay to reopen this one, or should I make a new post? – McM May 02 '20 at 07:58
  • What precisely are you still stuck on? Have you managed to get _Eigen_ recognized by your compiler? – sinoroc May 02 '20 at 08:05
  • I have not. The linked question seems to be using Eigen specifically on a project in visual studio. I don't have a project I am using Eigen for.. I am trying to have the pip installer see Eigen. – McM May 02 '20 at 08:09
  • I voted to reopen. You should edit the question to make it more focused on the actual issue. Get _pip_ to compile _pygalmesh_ which depends on the C/C++ library _Eigen_. Or maybe start a fresh question, if we don't manage to get this one reopened. But also make sure to show what you have already tried to get _Eigen_ to the compiler. -- Have you seen this: https://github.com/nschloe/pygalmesh/issues/64 ? – sinoroc May 02 '20 at 08:19
  • You are using _anaconda_ or _conda_, right? Have you looked at those? https://anaconda.org/anaconda/eigen -- https://anaconda.org/conda-forge/eigen – sinoroc May 02 '20 at 08:24
  • _facepalm_ I swear I did my searching. lol... well, thank you. I thought it was lost. Now onto CGAL. – McM May 02 '20 at 08:27
  • Oh wow, that actually doesn't solve it. pygalmesh apparently is only installable using pip. And pip requires Eigen/Dense. And I can't find my setup.py file. – McM May 02 '20 at 08:29
  • @sinoroc, could you help me with the step: "added an environment variable 'EIGEN_INCLUDE_DIR' pointing to 'C:\Anaconda3\envs\py37\Library\include\eigen3'". I don't know where or how to add the env variable. – McM May 02 '20 at 08:41
  • This one doesn't seem to be all too bad as a resource (haven't checked it thoroughly but you can find many other explanations around): https://www.techjunkie.com/environment-variables-windows-10/ – sinoroc May 02 '20 at 11:26
  • Ah, okay. So it's just the system path. I understand. The problem now is that pygalmesh searches for 'Eigen/Dense' whereas a Windows PC uses ```\```, not ```/```. Thus, it seems the installer itself needs to be modified. I've found its github https://github.com/nschloe/pygalmesh. There is a setup.py there I could modify. Though, I do not know then how would install the package. Still with _pip_? – McM May 02 '20 at 17:29
  • 1
    The creator of pygalmesh is troubleshooting this problem now. See: https://github.com/nschloe/pygalmesh/issues/81 – McM May 02 '20 at 17:50

2 Answers2

4

This solution worked on Windows 10, with python 3.8 and Visual Studio Community 2019 installed.

  1. Install dependencies: gmp, mpfr, eigen3 and cgal. I recommend vcpkg for libs build and installation, as described below. You also can install and build these dependencies separately your own way, without vcpkg.

    1.1. Install vcpkg (https://vcpkg.io/en/getting-started.html).

    1.2. Install dependencies on x64 static configuration:

    vcpkg install gmp:x64-windows-static
    vcpkg install mpfr:x64-windows-static
    vcpkg install eigen3:x64-windows-static
    vcpkg install cgal:x64-windows-static
    
  2. Clone pygalmesh sources:

    git clone https://github.com/nschloe/pygalmesh.git
    
  3. Add library_dirs=["C:/path/to/vcpkg/installed/x64-windows-static/lib"] to pygalmesh/setup.py (see Modified setup.py below the post, also check Alternative solution). Don't forget to insert your own vcpkg location instead of my /path/to/vcpkg.

  4. Build and install pygalmesh:

    cd pygalmesh
    set EIGEN_INCLUDE_DIR=C:/path/to/vcpkg/installed/x64-windows-static/include
    pip install .
    
  5. Make sure pygalmesh is installed:

    python
    >>> import pygalmesh
    

    enter image description here

Modified setup.py

import os

from pybind11.setup_helpers import Pybind11Extension, build_ext
from setuptools import setup

# https://github.com/pybind/python_example/
ext_modules = [
    Pybind11Extension(
        "_pygalmesh",
        # Sort input source files to ensure bit-for-bit reproducible builds
        # (https://github.com/pybind/python_example/pull/53)
        sorted(
            [
                "src/generate.cpp",
                "src/generate_2d.cpp",
                "src/generate_from_inr.cpp",
                "src/generate_from_off.cpp",
                "src/generate_periodic.cpp",
                "src/generate_surface_mesh.cpp",
                "src/remesh_surface.cpp",
                "src/pybind11.cpp",
            ]
        ),
        include_dirs=[os.environ.get("EIGEN_INCLUDE_DIR", "/usr/include/eigen3/")],
        # no CGAL libraries necessary from CGAL 5.0 onwards
        libraries=["gmp", "mpfr"],
        
        # !!! ADD YOUR PATH HERE !!!
        library_dirs=["C:/D/Apps/vcpkg/installed/x64-windows-static/lib"]
    )
]

if __name__ == "__main__":
    setup(
        cmdclass={"build_ext": build_ext},
        ext_modules=ext_modules,
        zip_safe=False,
    )

Alternative solution

In fact, pip has command line arguments to point to library paths (--global-option=build_ext, --include-path, --library-path see pip docs and this post), and a potential installation could be a pair of lines (after step 1 with C++ libs installation):

set EIGEN_INCLUDE_DIR=C:/path/to/vcpkg/installed/x64-windows-static/include
pip install --global-option=build_ext --install-option="--include-path=C:\path\to\vcpkg\installed\x64-windows-static\include" --global-option="--library-path=C:\path\to\vcpkg\installed\x64-windows-static\lib"  pygalmesh

BUT. By some reason (may be it's only my system configuration feature, or setuptools==58.1.0 version-specific "feature") setuptools don't put --library-path arguments to /LIBPATH: key of MSVC link.exe when building the package, which leads to LNK error.

Ornstein89
  • 598
  • 1
  • 6
  • 15
2

After raising the issue on the pygalmesh github, the community and creator solved the problem. See here. Simply:

conda install -c conda-forge pygalmesh
McM
  • 471
  • 5
  • 21
  • 1
    The issue with this is that it installed an older version, which raises some errors when certain functions are called. E.g. trying the first example on the github page raises the error "generate_2d() got an unexpected keyword argument 'max_edge_size'". Is it possible to install the version that the docs are updated for on windows? – hex93 Jun 07 '21 at 12:20