stable-diffusion-webui-depthmap-script icon indicating copy to clipboard operation
stable-diffusion-webui-depthmap-script copied to clipboard

Extension not working on Mac M2 Max

Open darkwood-studios opened this issue 2 years ago • 3 comments

*** Error loading script: depthmap_api.py Traceback (most recent call last): File "/Users/daniel/stable-diffusion-webui/modules/scripts.py", line 469, in load_scripts script_module = script_loading.load_module(scriptfile.path) File "/Users/daniel/stable-diffusion-webui/modules/script_loading.py", line 10, in load_module module_spec.loader.exec_module(module) File "", line 883, in exec_module File "", line 241, in _call_with_frames_removed File "/Users/daniel/stable-diffusion-webui/extensions/stable-diffusion-webui-depthmap-script/scripts/depthmap_api.py", line 16, in from src.core import core_generation_funnel, run_makevideo File "/Users/daniel/stable-diffusion-webui/extensions/stable-diffusion-webui-depthmap-script/src/core.py", line 27, in from inpaint.mesh import write_mesh, read_mesh, output_3d_photo File "/Users/daniel/stable-diffusion-webui/extensions/stable-diffusion-webui-depthmap-script/inpaint/mesh.py", line 12, in from vispy import scene, io File "/Users/daniel/stable-diffusion-webui/venv/lib/python3.10/site-packages/vispy/init.py", line 27, in from .util import config, set_log_level, keys, sys_info # noqa File "/Users/daniel/stable-diffusion-webui/venv/lib/python3.10/site-packages/vispy/util/init.py", line 14, in from . import fonts # noqa File "/Users/daniel/stable-diffusion-webui/venv/lib/python3.10/site-packages/vispy/util/fonts/init.py", line 13, in from ._triage import _load_glyph, list_fonts # noqa, analysis:ignore File "/Users/daniel/stable-diffusion-webui/venv/lib/python3.10/site-packages/vispy/util/fonts/_triage.py", line 14, in from ._quartz import _load_glyph, _list_fonts File "/Users/daniel/stable-diffusion-webui/venv/lib/python3.10/site-packages/vispy/util/fonts/_quartz.py", line 12, in from ...ext.cocoapy import cf, ct, quartz, CFRange, CFSTR, CGGlyph, UniChar,
File "/Users/daniel/stable-diffusion-webui/venv/lib/python3.10/site-packages/vispy/ext/cocoapy.py", line 1288, in quartz = cdll.LoadLibrary(util.find_library('quartz')) File "/opt/homebrew/Cellar/[email protected]/3.10.13_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ctypes/init.py", line 452, in LoadLibrary return self._dlltype(name) File "/opt/homebrew/Cellar/[email protected]/3.10.13_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ctypes/init.py", line 374, in init self._handle = _dlopen(self._name, mode) OSError: dlopen(Quartz.framework/Quartz, 0x0006): tried: 'Quartz.framework/Quartz' (no such file), '/System/Volumes/Preboot/Cryptexes/OSQuartz.framework/Quartz' (no such file), '/opt/homebrew/lib/Quartz.framework/Quartz' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/lib/Quartz.framework/Quartz' (no such file), '/usr/lib/Quartz.framework/Quartz' (no such file, not in dyld cache), 'Quartz.framework/Quartz' (no such file)

darkwood-studios avatar Jan 10 '24 13:01 darkwood-studios

I'm seeing the same behaviour w/ Sonoma 14.2.1

In the system frameworks strangely I see a broken link to the /Quartz subdir:

image

My understanding is that this should be part of the OS frameworks, but I can see no relevant directory to update the link to.

joelmgallant avatar Jan 17 '24 15:01 joelmgallant

I have this running on a 16" MacBook Pro with an M2 processor and Sonoma 14.2.1.

I only recently obtained this machine and access to local AI/ML tools so my experience is not very deep yet. However, I do have experience writing and troubleshooting software.

Background:

  • I have the stable-diffusion-webui installed in my user directory (~) at the moment
  • I'm using a Python virtual environment that gets stored in a .venv directory in stable-diffusion-webui
  • I installed stable-diffusion-webui using this guide https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Installation-on-Apple-Silicon for a "New install"
  • I have a host of other developer tools that are not standard on the system installed - hopefully these don't contribute to the success
  • I have a customized webui-user.sh file with these customizations:

export COMMANDLINE_ARGS="--theme dark --skip-torch-cuda-test --upcast-sampling --no-half-vae --use-cpu interrogate"

venv_dir="${install_dir}/${clone_dir}/.venv"

These are not necessary as far as I know, especially the .venv mod. I just want to help anybody else who lands here understand how I got to functional.

It's important to understand that I modified a package outside of stable-diffusion-webui to make this work. If you have other Python code, and you're not using virtual environments of some sort, you may break other things by doing this...or you may accidentally fix them 😂

As described by the accepted answer at stackoverflow ...

"This error is because Big Sur no longer has the OpenGL library nor other system libraries in standard locations in the file system and instead uses a cache. PyOpenGL uses ctypes to try to locate the OpenGL library and it fails to find it."

The correct answer also mentions ...

"So a future version of Python should resolve the problem."

But I wouldn't hold out for this since Python has already had new versions since, and stable-diffusion-webui is built around an older version.

Here's what I did:

  1. Shut down the webui in the browser and the terminal if you have it running
  2. Find the correct cocoapy.py - this belongs to the Vispy package that Depth Map uses - based on my install this is the file ~/stable-diffusion-webui/.venv/lib/python3.10/site-packages/vispy/ext/cocoapy.py
  3. Open cocoapy.py in your editor of choice
  4. Line 1288 of cocoapy.py looks like this quartz = cdll.LoadLibrary(util.find_library('quartz'))
  5. I commented the original line 1288 out so that it now looks like this #quartz = cdll.LoadLibrary(util.find_library('quartz'))
  6. Make a new line below the code at line 1288 and paste this code quartz = cdll.LoadLibrary(util.find_library('/System/Library/Frameworks/Quartz.framework/Quartz'))
  7. Save the changes to cocoapy.py
  8. Reload stable-diffusion-webui and you should now have a tab for Depth

I successfully generated a test depth map on an image after I did this.

myspoonistoobig avatar Jan 18 '24 22:01 myspoonistoobig

^ incredible writeup and workaround - editing cocoapy.py in the dependencies worked great for me - thanks @myspoonistoobig !

Some further reading re: library cache that I found helpful: https://forums.developer.apple.com/forums/thread/655588

joelmgallant avatar Jan 19 '24 15:01 joelmgallant