Error with "dwi2response"

Dear MRtrix3 community,

I’m wondering if you could help me to solve this problem:

Your help is well appreciated.

Best,
Alessio

OK, this is the same issue as your other problem when building MRtrix. The issue is that macOS no longer comes with Python 2.7 by default, and while python3 is installed (at least in your case), there is no python executable as such (only python3). So this means our scripts can’t find a suitable python interpreter, which we expect to be called simply python. I suspect this will cause headaches for a lot of people – not just MRtrix users…

There are a number of ways of fixing this, I’ll list a few here. Note that you should only need to do one of them, but the first one may not work (it’s fairly harmless though, but also very easy to revert if needed).


Use an alias:

I’m not sure this will work, but I have seen it suggested on a number of forums. The idea is to set up an alias called python that the shell (zsh) will translate into python3 for you on the fly. But that’s not guaranteed to work on the shebang line as we do here. It’s the simplest solution, and if it works, that’s great. I’m listing other solutions below in case it doesn’t.

Basically, edit your shell startup file (by default, this is ~/.zshrc if you use `zsh):

nano ~/.zshrc

and add this line at the end:

alias python=python3

Save, start a fresh terminal, and see if that fixes the issue…


Modify the script shebang line:

You can modify our scripts to refer to the right version. Basically, go through all the files in the bin/ folder of your MRtrix install, and identify the python scripts. They should all start with the line

#!/usr/bin/env python

Simply modify each of these scripts using your text editor by adding a 3 at the end, so that these lines now read:

#!/usr/bin/env python3

The problem with this approach is that this modifies the sources and won’t survive an update. You’ll need to do this every time you upgrade.


Create a symbolic link:

Add a symbolic link called python pointing to your actual python executable. The simplest way to achieve this is probably using this simple one-liner:

sudo ln -s $(which python3) /usr/bin/python

Note that this requires admin rights, which is why the command is prefixed with sudo, and it will ask you for your credentials.

This will work and survive updates, but there is a slight chance that it might interfere with other commands that expect python to correspond to version 2.7, not version 3. But then, these commands won’t currently work anyway as things stand, since you don’t have version 2.7 installed anyway…

To revert, you can simply delete the file it just created:

sudo rm /usr/bin/python

(only use that if there was no previous python executable at that location though!).


Hopefully one of these approaches will work… It would be good to have a seamless solution to this problem. We have discussed the issue several times over the years, and I don’t think there’s a clean solution that will work for everyone, unfortunately…

I’m trying to use the alias but I don’t know if I’m doing it right
After this command “nano ~/.zshrc”, this window have appeared:

Now, I have to write the second command or I have to do another thing?

Yep, just copy / paste:

alias python=python3

in there, then type Ctrl-O to save, and Ctrl-X to exit. :+1:

I did it, but I have the same error

I tried the third solution(Create a symbolic link) but I had this problem (even if I wrote the password):

OK, as I’d mentioned, I thought that first option (using an alias) was unlikely to work – I only included it because I’d seen it suggested in so many places…

For that last one, do you have admin rights on your system? For example, can you run e.g. this command:

sudo ls

If not, maybe you need to figure out whether you can run a Terminal as admin – though I have no idea about that as I’ve never used macOS myself…

Maybe other mac users can help out here…? :grimacing: