Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension not working on Mac M2 Max #397

Open
darkwood-studios opened this issue Jan 10, 2024 · 3 comments
Open

Extension not working on Mac M2 Max #397

darkwood-studios opened this issue Jan 10, 2024 · 3 comments

Comments

@darkwood-studios
Copy link

*** 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/python@3.10/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/python@3.10/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)

@joelmgallant
Copy link

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.

@myspoonistoobig
Copy link

myspoonistoobig commented Jan 18, 2024

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.

@joelmgallant
Copy link

^ 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants