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

No blender installation found #205

Closed
gaetgu opened this issue Jun 1, 2021 · 2 comments · May be fixed by #353
Closed

No blender installation found #205

gaetgu opened this issue Jun 1, 2021 · 2 comments · May be fixed by #353

Comments

@gaetgu
Copy link

gaetgu commented Jun 1, 2021

Hi! I am having some issues with loading blender files. I am trying to load a (fairly complicated, not too bad) blender file, but ursina bombs with this error:

Traceback (most recent call last):
  File "/Users/***/main.py", line 4, in <module>
    e = Entity(model = 'car')
  File "/Users/***/Library/Python/3.8/lib/python/site-packages/ursina/entity.py", line 102, in __init__
    setattr(self, key, value)
  File "/Users/***/Library/Python/3.8/lib/python/site-packages/ursina/entity.py", line 177, in __setattr__
    m = load_model(value, application.asset_folder)
  File "/Users/***/Library/Python/3.8/lib/python/site-packages/ursina/mesh_importer.py", line 62, in load_model
    if compress_models(path=path, name=name):
  File "/Users/***/Library/Python/3.8/lib/python/site-packages/ursina/mesh_importer.py", line 181, in compress_models
    blender = get_blender(blend_file)
  File "/Users/***/Library/Python/3.8/lib/python/site-packages/ursina/mesh_importer.py", line 156, in get_blender
    raise Exception('error: trying to load .blend file, but no blender installation was found.')
Exception: error: trying to load .blend file, but no blender installation was found.

(for reference this is the code running it all)

from ursina import *
app = Ursina()

e = Entity(model = 'castaway_island')

app.run()

It seems to think that I don't have blender installed??? I do, here is a ss of it displaying the same model I am trying to load:
Screen Shot 2021-05-31 at 7 06 47 PM

I am not really sure why this is happening, so any help is greatly appreciated!

Info:

  • macOS 11.4
  • MacBook Air (M1, 2020)
  • Python 3.8.2
@jingfu-wei
Copy link

I just encountered the same issue.

I dived into the sourced code and found that Ursina locates Blender installation in ursina/mesh_importer.py at line 70ish. It called platform.system() to determin the OS, whereas it only took Windows and Linux into account, hence the issue we met.
Here is the code snippet where the issue arised:

if application.development_mode:

    if platform.system() == 'Windows':
        # get blender path by getting default program for '.blend' file extention
        import shlex
        import winreg

        try:
            class_root = winreg.QueryValue(winreg.HKEY_CLASSES_ROOT, '.blend')
            with winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, r'{}\shell\open\command'.format(class_root)) as key:
                command = winreg.QueryValueEx(key, '')[0]
                default_blender = shlex.split(command)[0]
                default_blender = Path(default_blender)
                application.blender_paths['default'] = default_blender
                blender_foundation_directory = default_blender.parent.parent

                for blender_installation in blender_foundation_directory.glob('*'):
                    first_folder = tuple(blender_installation.glob('*'))[0] # version
                    version_name = first_folder.name[:3]
                    application.blender_paths[version_name] = list(blender_installation.glob('blender.exe'))[0]
        except:
            pass

    elif platform.system() == 'Linux':
        # Use "which" command to find blender
        which_process = subprocess.run(('which', 'blender'), stdout=subprocess.PIPE)
        if which_process.returncode == 0:
            blender_exec = which_process.stdout.decode().strip()
            application.blender_paths['default'] = blender_exec

Because if you call platform.system() on a mac, it will return 'Darwin' (at least on my Mac it did)

image

The logic behind locating Blender in Ursina is straightforward: use subprocess.run() to execute which blender, and set the standard output as the path to blender. Ursina stores the path with a dict named blender_paths in ursina/application.py.

Here is my solution:

  1. Identify the location of Blender excutable; in my case, it is /Applications/Blender.app/Contents/MacOS/Blender
  2. Open your terminal, and run: ln -s YOUR_BLENDER_EXCUTABLE_PATH /usr/local/bin, which will create a symbolic link to the Blender executable
  3. Test in terminal with which blender, which should return the path to the link just created. Run blender and Blender should be launched.
  4. Add following line in ursina/mesh_importer.py after the snippet I put above (or if you prefer, replce elif statement with a simple else:
    elif platform.system() == 'Darwin':
        which_process = subprocess.run(('which', 'blender'), stdout=subprocess.PIPE)
        if which_process.returncode == 0:
            blender_exec = which_process.stdout.decode().strip()
            application.blender_paths['default'] = blender_exec
  1. Try to load your .blend file again, and upon executing the app, you should be able to see this in your console:
blender_paths:
{'default': '/usr/local/bin/blender'}
  1. If it shows the path correctly, it should work well.

@gaetgu
Copy link
Author

gaetgu commented Jun 1, 2021

Thanks so much! It did indeed work.

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

Successfully merging a pull request may close this issue.

2 participants