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

Unable to use blender via cortex.segment.cut_surface #377

Closed
jsmentch opened this issue Oct 29, 2020 · 4 comments
Closed

Unable to use blender via cortex.segment.cut_surface #377

jsmentch opened this issue Oct 29, 2020 · 4 comments

Comments

@jsmentch
Copy link

I've been trying to use the cut_surface function but receive the following error:
FileNotFoundError: [Errno 2] No such file or directory: b'blender'

I've installed blender and also set up a bash alias for 'blender' to open my blender app. Has anyone else encountered this error or know a solution? I am running trying to run this w/ python 3.8 on Mac Mojave, Blender v2.90.1
Thanks!

More detail:

In [2]: cortex.segment.cut_surface('sub-19', 'lh', name='flatten', fs_subject='s
   ...: ub-19', data=None, freesurfer_subject_dir='/Users/jeff/Documents/project
   ...: s/pycortex/derivatives/freesurfer', flatten_with='freesurfer', do_import
   ...: _subject=True)
b'created by jsmentch on Thu Sep 17 17:38:19 2020\n'
b'\n'
Vert check ok!
b'created by jsmentch on Thu Sep 17 17:37:13 2020\n'
b'created by jsmentch on Thu Sep 17 17:38:19 2020\n'
In new named temp file: /var/folders/py/jwmbjksd31d0pl24f5r0xvm00000gn/T/tmpxr3z5uj5
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-2-6f1fc6f490b8> in <module>
----> 1 cortex.segment.cut_surface('sub-19', 'lh', name='flatten', fs_subject='sub-19', data=None, freesurfer_subject_dir='/Users/jeff/Documents/projects/pycortex/derivatives/freesurfer', flatten_with='freesurfer', do_import_subject=True)

/opt/miniconda3/envs/pycortex/lib/python3.8/site-packages/cortex/segment.py in cut_surface(cx_subject, hemi, name, fs_subject, data, freesurfer_subject_dir, flatten_with, do_import_subject, **kwargs)
    180         print('Vert check ok!')
    181     if not os.path.exists(fname):
--> 182         blender.fs_cut(fname, fs_subject, hemi, freesurfer_subject_dir)
    183     # Add localizer data to facilitate cutting
    184     if data is not None:

/opt/miniconda3/envs/pycortex/lib/python3.8/site-packages/cortex/blender/__init__.py in fs_cut(fname, subject, hemi, freesurfer_subject_dir)
    166             blendlib.init_subject(wpts, ipts, polys, curv)
    167         """.format(tfname=tf.name)
--> 168         _call_blender(fname, code)
    169
    170 def write_patch(bname, pname, mesh="hemi"):

/opt/miniconda3/envs/pycortex/lib/python3.8/site-packages/cortex/blender/__init__.py in _call_blender(filename, code, blender_path)
     39         tf.write((startcode+code+endcode).encode())
     40         tf.flush()
---> 41         sp.check_call([w.encode() for w in shlex.split(cmd)],)
     42
     43 def add_cutdata(fname, braindata, name="retinotopy", projection="nearest", mesh="hemi"):

/opt/miniconda3/envs/pycortex/lib/python3.8/subprocess.py in check_call(*popenargs, **kwargs)
    357     check_call(["ls", "-l"])
    358     """
--> 359     retcode = call(*popenargs, **kwargs)
    360     if retcode:
    361         cmd = kwargs.get("args")

/opt/miniconda3/envs/pycortex/lib/python3.8/subprocess.py in call(timeout, *popenargs, **kwargs)
    338     retcode = call(["ls", "-l"])
    339     """
--> 340     with Popen(*popenargs, **kwargs) as p:
    341         try:
    342             return p.wait(timeout=timeout)

/opt/miniconda3/envs/pycortex/lib/python3.8/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    852                             encoding=encoding, errors=errors)
    853
--> 854             self._execute_child(args, executable, preexec_fn, close_fds,
    855                                 pass_fds, cwd, env,
    856                                 startupinfo, creationflags, shell,

/opt/miniconda3/envs/pycortex/lib/python3.8/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1700                     if errno_num != 0:
   1701                         err_msg = os.strerror(errno_num)
-> 1702                     raise child_exception_type(errno_num, err_msg, err_filename)
   1703                 raise child_exception_type(err_msg)
   1704

FileNotFoundError: [Errno 2] No such file or directory: b'blender'

@mvdoc
Copy link
Contributor

mvdoc commented Oct 29, 2020

I haven't tried this on a mac, but it could be an issue about your path and mac os x. I don't think aliases get loaded within your python session. According to the blender docs (https://docs.blender.org/manual/en/latest/advanced/command_line/launch/macos.html) you can add the following to your PATH

echo "export PATH="$PATH:/Applications/Blender.app/Contents/MacOS" >> ~/.bash_profile

however, annoyingly blender's command line in mac is called Blender instead of blender, so cut_surface might still fail.

The easiest option for you (before we decide how to fix this to support both mac and linux) is to create a symlink to /Applications/Blender.app/Contents/MacOS/Blender in a path that gets loaded by your bash. For example, assuming you have ~/bin in your path, you could do the following

ln -s /Applications/Blender.app/Contents/MacOS/Blender ~/bin/blender

and that might work.

@jsmentch
Copy link
Author

Thanks for the help!!

I gave that a try and unfortunately blender doesn't seem to like opening via symlinks, same issue encountered as here: pelednoam/mmvt#190

I'm not tied down to mac so maybe linux is a better route until that is fixed. I actually first attempted to install in a singularity img (ubuntu, also tried centos) but was running into failed building wheel problems. Also tried an image on dockerhub (I think it was actually your image!) but seemed to be an older python 2 version and couldn't get it and jupyter,freesurfer quite working.

I will ideally try to install pycortex in singularity again soon, do you happen to know if there is a recommended easiest or standard system and version to install? Like ubuntu xenial/ python3.x / etc? Or has anyone else run into failed building wheel problems and know of a solution? Probably some error on my end.

@marklescroart
Copy link
Contributor

marklescroart commented Oct 30, 2020

Sorry for the slow response - this should be fixable on Mac, but unfortunately you will likely run into other problems once you fix it (see below). There is a field in the config file under the [dependency_paths] section in which you can specify the path to the binary executable file for blender. If you've never touched it, you can find the path to your config file by calling:
cortex.options.usercfg. You can edit it in any plain text editor. By default, the path to blender is set to just blender, which will get you to the binary file if it is indeed called blender and it is on your path, as it is on Linux. For MacOS, you'll need to provide the path to the executable binary in that field. For me, it's:
[dependency_paths]
...
blender=/Applications/Blender.app/Contents/MacOS/Blender

This is actually spelled out in the default config file, here: https://github.com/gallantlab/pycortex/blob/master/cortex/defaults.cfg

Of course: pycortex does not yet work with blender 2.8, much less with blender 2.9, because of changes in the blender python API from 2.7 to 2.8. You can work around this by downloading a legacy version of Blender (probably 2.79) from here and pointing the config file to the executable binary with that app package, wherever you put it. It is on my list to fix this (see #349), but I have two small kids and a pretty new lab of my own and there's a pandemic. So it may be a while. Apologies.

@jsmentch
Copy link
Author

jsmentch commented Nov 2, 2020

Thanks for your response!

Ah, I see, I missed that issue and didn't realize blender 2.79 was needed. Things seem to be working based on those changes, at least I am now in blender via segment.cut_surface and editing the surface! I did edit the config file earlier but was not aware of that default file with those comments. If I get this working/figured out and if it's ok, I will perhaps make a pr to the docs/installation instructions to add some of this info, as it was very helpful and I think would help others getting set up!

@jsmentch jsmentch closed this as completed Nov 2, 2020
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