2
$\begingroup$

I'd like to run Blender from the command line (like this) in Mac OS, but am running into an error which causes Blender to crash each time I run ./blender (from within /Applications/Blender/blender.app/Contents/MacOS):

Jamies-MBP:MacOS Jamie$ ./blender
ndof: 3Dx driver not found
Read new prefs: /Users/Jamie/Library/Application Support/Blender/2.74/config/userpref.blend
found bundled python: /Applications/Blender/blender.app/Contents/MacOS/../Resources/2.74/python
Fatal Python error: Py_Initialize: unable to load the file system codec
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/__init__.py", line 123
    raise CodecRegistryError,\
                            ^
SyntaxError: invalid syntax
Illegal instruction: 4

The OS also reports that 'Blender quit unexpectedly.'

The error seems to suggest that Blender is looking for Python 2.7, but I thought Blender would always use its own copy of Python 3? If I run which python I get /usr/bin/python, and if I run which python3 I get /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.

If I run $PYTHONPATH the output looks like this:

-bash: /Library/Python/2.7/site-packages/pip-1.4.1-py2.7.egg:
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip:
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7:
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin:
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac:
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages:
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python:
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk:
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old:
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload:
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC:
/Library/Python/2.7/site-packages:
/Library/Python/2.7/site-packages/PIL: No such file or directory

I'm not sure whether this is typical or not (there seems to be an No such file or directory error but I don't know if that's related).

What should I do to fix this or investigate this further? Do I need to add python3 to my $PYTHONPATH? This answer mentions other variables, such as $BLENDER_SYSTEM_PYTHON – do I need to change this?

$\endgroup$

2 Answers 2

2
$\begingroup$

Well the solution for me was to unset my $PYTHONPATH, which was configured to create the output listed above by a line in my ~/.bash_profile file.

When started from the Terminal, Blender now still loads the bundled Python:

found bundled python: /Applications/Blender/blender.app/Contents/MacOS/../Resources/2.74/python

But Python is now able to load the modules it needs. I guess that having $PYTHONPATH set was preventing Blender's Python from being able to load required modules.

$\endgroup$
1
  • $\begingroup$ I had a similar problem, but Python 2.7 path wasn't in my PYTHONPATH , but in in my PATH environnement variable. Thank you for pointing me the right .. path :P $\endgroup$ Commented Jun 29, 2018 at 8:40
0
$\begingroup$

This was one of the top answers for me when I had the same problem; here's what my issue was:

I made a hard link between my Blender download (which I put in /opt/blender) and my /usr/local/bin folder. With the hard link the executable isn't able to find the Python files it needs in its own subdirectory because it's looking for them in /usr/local/bin instead of where they're actually located, which is /opt/blender/3.0/python, etc.

First I had to remove the hard link:

sudo rm /usr/local/bin/blender

And then I had to remake it as a symbolic link:

sudo ln -s /opt/blender/blender /usr/local/bin/blender

The -s flag in the ln link command is what creates a symbolic link and it's the difference between the error OP gave and Blender starting correctly.

Pro tip, too: If you're getting Unity errors where Blender could not be launched after you've done this then you need to right-click the Assets folder in the Unity Editor and "Reimport All".

$\endgroup$
1
  • $\begingroup$ Check where your blender file is being invoked with which blender. The whole blender install shouldn't be at that path, which means that whatever result you get from that command should be the SYMOBLIC link. If you check it with ls -l /path/you/were/given and it doesn't show a link back to your Blender install then you need to do the steps above. $\endgroup$
    – Chuck
    Commented Jan 25, 2022 at 18:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .