pygfx / wgpu-py

WebGPU for Python
https://wgpu-py.readthedocs.io
BSD 2-Clause "Simplified" License
440 stars 34 forks source link

Mac M1 support #136

Closed anentropic closed 3 years ago

anentropic commented 3 years ago

Overview (edited by AK):


I was getting this error:

  • Installing wgpu (0.3.0): Failed

  EnvCommandError

  Command ['/Users/anentropic/Library/Caches/pypoetry/virtualenvs/hexblade-gi2zk5D5-py3.9/bin/pip', 'install', '--no-deps', 'file:///Users/anentropic/Library/Caches/pypoetry/artifacts/aa/f3/b2/8caef6980405490715f8040d2349bddb320b3962d15c24f0525b66d749/wgpu-0.3.0.tar.gz'] errored with the following return code 1, and output:
  Processing /Users/anentropic/Library/Caches/pypoetry/artifacts/aa/f3/b2/8caef6980405490715f8040d2349bddb320b3962d15c24f0525b66d749/wgpu-0.3.0.tar.gz
      ERROR: Command errored out with exit status 1:
       command: /Users/anentropic/Library/Caches/pypoetry/virtualenvs/hexblade-gi2zk5D5-py3.9/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/w1/_vgkxyln4c7bk8kr29s1y1k00000gn/T/pip-req-build-99e_f9gh/setup.py'"'"'; __file__='"'"'/private/var/folders/w1/_vgkxyln4c7bk8kr29s1y1k00000gn/T/pip-req-build-99e_f9gh/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/w1/_vgkxyln4c7bk8kr29s1y1k00000gn/T/pip-pip-egg-info-23tylv6i
           cwd: /private/var/folders/w1/_vgkxyln4c7bk8kr29s1y1k00000gn/T/pip-req-build-99e_f9gh/
      Complete output (5 lines):
      Traceback (most recent call last):
        File "<string>", line 1, in <module>
        File "/private/var/folders/w1/_vgkxyln4c7bk8kr29s1y1k00000gn/T/pip-req-build-99e_f9gh/setup.py", line 6, in <module>
          from wheel.pep425tags import get_platform
      ModuleNotFoundError: No module named 'wheel.pep425tags'

https://nomodulenamed.com/m/wheel.pep425tags says:

This is probably because you don't have package wheel installed.

But:

Python 3.9.2 (default, Mar 18 2021, 20:48:06)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from wheel.pep425tags import get_platform
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'wheel.pep425tags'
>>> import wheel
>>> wheel.__version__
'0.36.2'
>>> exit()

https://wheel.readthedocs.io/en/stable/news.html

0.35.0 (2020-08-13) Switched to the packaging library for computing wheel tags

...sounded possibly relevant. The previous version to that is 0.34.2

which was also mentioned on the nomodulenamed page

And yes, this fixed it:

% pip install wheel==0.34.2
Collecting wheel==0.34.2
  Downloading wheel-0.34.2-py2.py3-none-any.whl (26 kB)
Installing collected packages: wheel
  Attempting uninstall: wheel
    Found existing installation: wheel 0.36.2
    Uninstalling wheel-0.36.2:
      Successfully uninstalled wheel-0.36.2
Successfully installed wheel-0.34.2
% python
Python 3.9.2 (default, Mar 18 2021, 20:48:06)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import wheel
>>> wheel.__version__
'0.34.2'
>>> from wheel.pep425tags import get_platform
>>> exit()

and poetry install then succeeded.

I'm not totally sure where the problem originates, whether you need to pin wheel==0.34.2 in your setup.py or some other part of the build machinery is to blame.

(Pinning wheel==0.34.2 in my pyproject.toml didn't help, because Poetry didn't know about the dependency relationship and tries to install wgpu first... so for now it's fixed by manually installing old wheel version in my virtualenv)

Just posting this in case it helps someone else.

almarklein commented 3 years ago

I prefer to keep this open until @marcdownie (and others?) can confirm it also works for them.

We can still do a new release in the meantime with what we have now - would also make it easier for others to test it.

Korijn commented 3 years ago

I prefer to keep this open until @marcdownie (and others?) can confirm it also works for them.

We can still do a new release in the meantime with what we have now - would also make it easier for others to test it.

Let's do that!

marcdownie commented 3 years ago

I'm back (sorry about the pause); and I'm up to date with main, out of conda, using the pre-release pip cffi, not having an x64 parallel brew installation any more, and ... I'm still on the cffi python MemoryError.

marcdownie commented 3 years ago

The MemoryError is the only remaining issue at this point, and so far only @marcdownie has reported it with a conda environment...

To be clear (because this is quite the issue!) I was only not getting the MemoryError in my base conda; I've never made it past the MemoryError outside of a conda environment. And, this morning, after much uninstalling bits of my system, now even conda is throwing the MemoryError.

marcdownie commented 3 years ago

Results! I walked away from my python superfund site onto a fresh machine. Either the prerelease cffi, or the lack of detritus left over from x64 brew, is in fact the missing ingredient.

WGPU_BACKEND_TYPE=Metal PYGLFW_LIBRARY=/opt/homebrew/Cellar/glfw/3.3.4/lib/libglfw.3.3.dylib python3.9 examples/triangle_glfw.py

Gives me a triangle!

berendkleinhaneveld commented 3 years ago

Awesome! Too bad it's still a mystery as to what exactly causes the MemoryError, but at least you get to experience the triangle now!

marcdownie commented 3 years ago

I think the MemoryError is picking up the wrong ffi or trampoline lib, the one without Apple's secret write+execute trampoline sauce. The real mystery to me is how conda managed to move ahead of pip here, which led me to see a working triangle last week. I'd still feel better if I can verify that this all works in a fresh venv, but for now, I'm back to feeling ok about wgpu-py on M1. So a LGTM for this and #190 from me.

almarklein commented 3 years ago

There it is!

image