thegrill / grill

Cook digital.
MIT License
16 stars 5 forks source link

Can't build for mayapy #38

Closed SydneyED closed 12 months ago

SydneyED commented 12 months ago

Hi there, I'm struggling to build this for maya and was wondering if you'd be able to point me in the right direction.

I have successfully built your code on Windows from the powershell for importing to a stand-alone terminal by installing pygraphviz with: python -m pip install --use-pep517 --global-option=build_ext --global-option="-I.\Graphviz\include" --global-option="-L.\Graphviz\lib" pygraphviz

And your grill with: python -m pip install grill

However, when I then try to install with mayapy I get the following errors:

PS {USER}> mayapy -m pip install grill
Collecting grill
  Using cached grill-0.15.0-py3-none-any.whl (59 kB)
Collecting grill-names>=2.6.0 (from grill)
  Using cached grill_names-2.6.0-py3-none-any.whl (8.6 kB)
Collecting networkx (from grill)
  Using cached networkx-3.1-py3-none-any.whl (2.1 MB)
Collecting pygraphviz (from grill)
  Using cached pygraphviz-1.11.zip (120 kB)
  Preparing metadata (setup.py) ... done
Collecting numpy (from grill)
  Obtaining dependency information for numpy from https://files.pythonhosted.org/packages/cc/05/ef9fc04adda45d537619ea956bc33489f50a46badc949c4280d8309185ec/numpy-1.26.0-cp310-cp310-win_amd64.whl.metadata
  Using cached numpy-1.26.0-cp310-cp310-win_amd64.whl.metadata (61 kB)
Requirement already satisfied: naming>=0.6 in .\maya2024\python\lib\site-packages (from grill-names>=2.6.0->grill) (0.7.0)
Using cached numpy-1.26.0-cp310-cp310-win_amd64.whl (15.8 MB)
Building wheels for collected packages: pygraphviz
  Building wheel for pygraphviz (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [54 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-310
      creating build\lib.win-amd64-cpython-310\pygraphviz
      copying pygraphviz\agraph.py -> build\lib.win-amd64-cpython-310\pygraphviz
      copying pygraphviz\graphviz.py -> build\lib.win-amd64-cpython-310\pygraphviz
      copying pygraphviz\scraper.py -> build\lib.win-amd64-cpython-310\pygraphviz
      copying pygraphviz\testing.py -> build\lib.win-amd64-cpython-310\pygraphviz
      copying pygraphviz\__init__.py -> build\lib.win-amd64-cpython-310\pygraphviz
      creating build\lib.win-amd64-cpython-310\pygraphviz\tests
      copying pygraphviz\tests\test_attribute_defaults.py -> build\lib.win-amd64-cpython-310\pygraphviz\tests
      copying pygraphviz\tests\test_clear.py -> build\lib.win-amd64-cpython-310\pygraphviz\tests
      copying pygraphviz\tests\test_close.py -> build\lib.win-amd64-cpython-310\pygraphviz\tests
      copying pygraphviz\tests\test_drawing.py -> build\lib.win-amd64-cpython-310\pygraphviz\tests
      copying pygraphviz\tests\test_edge_attributes.py -> build\lib.win-amd64-cpython-310\pygraphviz\tests
      copying pygraphviz\tests\test_graph.py -> build\lib.win-amd64-cpython-310\pygraphviz\tests
      copying pygraphviz\tests\test_html.py -> build\lib.win-amd64-cpython-310\pygraphviz\tests
      copying pygraphviz\tests\test_layout.py -> build\lib.win-amd64-cpython-310\pygraphviz\tests
      copying pygraphviz\tests\test_node_attributes.py -> build\lib.win-amd64-cpython-310\pygraphviz\tests
      copying pygraphviz\tests\test_readwrite.py -> build\lib.win-amd64-cpython-310\pygraphviz\tests
      copying pygraphviz\tests\test_repr_mimebundle.py -> build\lib.win-amd64-cpython-310\pygraphviz\tests
      copying pygraphviz\tests\test_scraper.py -> build\lib.win-amd64-cpython-310\pygraphviz\tests
      copying pygraphviz\tests\test_string.py -> build\lib.win-amd64-cpython-310\pygraphviz\tests
      copying pygraphviz\tests\test_subgraph.py -> build\lib.win-amd64-cpython-310\pygraphviz\tests
      copying pygraphviz\tests\test_unicode.py -> build\lib.win-amd64-cpython-310\pygraphviz\tests
      copying pygraphviz\tests\__init__.py -> build\lib.win-amd64-cpython-310\pygraphviz\tests
      running egg_info
      writing pygraphviz.egg-info\PKG-INFO
      writing dependency_links to pygraphviz.egg-info\dependency_links.txt
      writing top-level names to pygraphviz.egg-info\top_level.txt
      reading manifest file 'pygraphviz.egg-info\SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      warning: no files found matching '*.png' under directory 'doc'
      warning: no files found matching '*.txt' under directory 'doc'
      warning: no files found matching '*.css' under directory 'doc'
      warning: no previously-included files matching '*~' found anywhere in distribution
      warning: no previously-included files matching '*.pyc' found anywhere in distribution
      warning: no previously-included files matching '.svn' found anywhere in distribution
      no previously-included directories found matching 'doc\build'
      adding license file 'LICENSE'
      writing manifest file 'pygraphviz.egg-info\SOURCES.txt'
      copying pygraphviz\graphviz.i -> build\lib.win-amd64-cpython-310\pygraphviz
      copying pygraphviz\graphviz_wrap.c -> build\lib.win-amd64-cpython-310\pygraphviz
      running build_ext
      building 'pygraphviz._graphviz' extension
      creating build\temp.win-amd64-cpython-310
      creating build\temp.win-amd64-cpython-310\Release
      creating build\temp.win-amd64-cpython-310\Release\pygraphviz
      ".\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.37.32822\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -DSWIG_PYTHON_STRICT_BYTE_CHAR -DGVDLL -I.\Maya2024\Python\include -I.\Maya2024\Python\Include "-I.\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.37.32822\include" "-I.\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\VS\include" "-I.\Windows Kits\10\include\10.0.22621.0\ucrt" "-I.\Windows Kits\10\\include\10.0.22621.0\\um" "-I.\Windows Kits\10\\include\10.0.22621.0\\shared" "-I.\Windows Kits\10\\include\10.0.22621.0\\winrt" "-I.\Windows Kits\10\\include\10.0.22621.0\\cppwinrt" "-I.\Windows Kits\NETFXSDK\4.8\include\um" /Tcpygraphviz/graphviz_wrap.c /Fobuild\temp.win-amd64-cpython-310\Release\pygraphviz/graphviz_wrap.obj
      graphviz_wrap.c
      pygraphviz/graphviz_wrap.c(168): fatal error C1083: Cannot open include file: 'Python.h': No such file or directory
      error: command '.\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.37.32822\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pygraphviz
  Running setup.py clean for pygraphviz
Failed to build pygraphviz
ERROR: Could not build wheels for pygraphviz, which is required to install pyproject.toml-based projects 

I have installed the MSVC 14+ 2022 Build Tools, I have tried with pep-517 and without pep-517, I've tried adding -I{Python library folders}, I've updated pip/setuptools/wheel.

When I install python-dev-tools with pip it deprecates the pip and causes legacy issues. But with the python-dev-tools it gives the cannot build wheel/cannot run setup.py cl.exe failed error.

I have installed Graphviz and can build_ext pygraphviz for external python, but not for Maya.

Have the build instructions changed since this was published? Is there a way to get this to run in Maya without having to build pygraphviz for it as the instructions say optional but I can't install without it?

OS: Windows 10, Python 310, Maya 2024

SydneyED commented 12 months ago

I'm using the most recent x64 version of GraphViz.

I have tried the python-dev install suggestion from here I have tried copying the instructions from here
I've tried installing using Christi Fati's pre-built binaries Tried the no-cache-dir option here Added GraphViz to PATH and tried to pip install the wheel file it built

chrizzFTD commented 12 months ago

Hi @SydneyED, thanks for looking into this project!

It's great to know that pygraphviz has worked on a standalone python environment. For Maya (via mayapy), what I've found to work is to add include and library paths from Maya itself (its Python and lib folders) apart from graphviz in the form of -I{graphviz\include};{maya\include} and -L{graphviz\lib};{maya\lib}, for example (shortened paths for brevity):

--global-option="-IC:\graphviz\...\include;C:\...\Maya2023\include\Python39\Python" --global-option="-LC:\graphviz\...\lib;C:\...\Maya2023\lib"

There's a small section on The Grill install docs with a snippet like this, which is what I've used for Maya-2023:

mayapy -m pip install --global-option=build_ext  --global-option="-IC:\graphviz\Library\include;C:\Program Files\Autodesk\Maya2023\include\Python39\Python" --global-option="-LC:\graphviz\Library\lib;C:\Program Files\Autodesk\Maya2023\lib" pygraphviz

If this continues to fail, the way right now to install grill without pygraphviz in Maya would be to exclude all dependencies with the --no-deps flag to pip:

mayapy -m pip install grill --no-deps

and then install the dependencies separately, excluding pygraphviz:

mayapy -m pip install grill-names networkx numpy

Is there a way to get this to run in Maya without having to build pygraphviz for it as the instructions say optional but I can't install without it?

You're right, the initial intention when I included graphviz was for it to be optional, the fact that there's no easy way to install without pygraphviz is an oversight, I'll look into addressing it in the future. In the meantime, I hope this helps! Please let me know how it goes if you get a chance at testing the above.

Cheers

SydneyED commented 12 months ago

Hi! Thank you so much for the quick response.

I am happy to report your snippet works when adjusted for 310 and Maya2024!! I apologise for I must've missed that particular snippet or I was pointing to the wrong folder in my own -I flags (I believe I was originally pointing to a Python header files directory further down the tree so thank you!).

For my install the file paths looked like the following (adjusted slightly for ease of reading/different install locations)

mayapy -m pip install --global-option=build_ext  --global-option="-IC:\...\Graphviz\include;.C:\..\Maya2024\include\Python310\Python" --global-option="-LC:\...\Graphviz\lib;C:\...\Maya2024\lib" pygraphviz

And I've just loaded up Maya2024 and the full menu is there, I look forward to trying out the functionality 👍 😄

Full output below:

PS C:\{USER}> mayapy -m pip install --global-option=build_ext  --global-option="-IC:\...\Graphviz\include;C:\...\Maya2024\include\Python310\Python" --global-option="-LC:\...\Graphviz\lib;C:\...\Maya2024\lib" pygraphviz
>>
DEPRECATION: --build-option and --global-option are deprecated. pip 23.3 will enforce this behaviour change. A possible replacement is to use --config-settings. Discussion can be found at https://github.com/pypa/pip/issues/11859
WARNING: Implying --no-binary=:all: due to the presence of --build-option / --global-option.
Collecting pygraphviz
  Using cached pygraphviz-1.11.zip (120 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: pygraphviz
  Building wheel for pygraphviz (setup.py) ... done
  Created wheel for pygraphviz: filename=pygraphviz-1.11-cp310-cp310-win_amd64.whl size=107859 sha256=b33bdf625544983e5e9bb8b8015008041f2f1a5b9584a2f89fb031d0d72ea2cc
  Stored in directory: c:\{USER}\appdata\local\pip\cache\wheels\5b\ee\36\f47a0d35664fbe1a2b5a433ae33c6ad636b00bb231f68a9aaa
Successfully built pygraphviz
Installing collected packages: pygraphviz
Successfully installed pygraphviz-1.11

PS C:\{USER}> mayapy -m pip install grill
Collecting grill
  Using cached grill-0.15.0-py3-none-any.whl (59 kB)
Collecting grill-names>=2.6.0 (from grill)
  Using cached grill_names-2.6.0-py3-none-any.whl (8.6 kB)
Collecting networkx (from grill)
  Using cached networkx-3.1-py3-none-any.whl (2.1 MB)
Requirement already satisfied: pygraphviz in c:\...\maya2024\python\lib\site-packages (from grill) (1.11)
Collecting numpy (from grill)
  Obtaining dependency information for numpy from https://files.pythonhosted.org/packages/cc/05/ef9fc04adda45d537619ea956bc33489f50a46badc949c4280d8309185ec/numpy-1.26.0-cp310-cp310-win_amd64.whl.metadata
  Using cached numpy-1.26.0-cp310-cp310-win_amd64.whl.metadata (61 kB)
Requirement already satisfied: naming>=0.6 in c:\...\maya2024\python\lib\site-packages (from grill-names>=2.6.0->grill) (0.7.0)
Using cached numpy-1.26.0-cp310-cp310-win_amd64.whl (15.8 MB)
Installing collected packages: numpy, networkx, grill-names, grill
  WARNING: The script f2py.exe is installed in 'C:\...\Maya2024\Python\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed grill-0.15.0 grill-names-2.6.0 networkx-3.1 numpy-1.26.0
chrizzFTD commented 11 months ago

That's great to read and awesome that it's working for Maya2024; thanks for confirming the update, @SydneyED! 😃