I have a r2 script that I'm running with r2 -i script.py test.x. By default this command uses python2. How can I get it to use python3? I couldn't find anything in the config.


OP did not mention their OS, thus I assume the OS is Linux.

radare2 is using the default python version on your machine. That means that, probably, /usr/bin/python on your machine points to /usr/bin/python2.7. You can check it by executing readlink on the file:

$ readlink -f /usr/bin/python

The solution for this should be quite straightforward. Simply, changing where python points to should do the trick. You can do this by executing ln and point python to python3 on your machine:

$ sudo ln -sf /usr/bin/python3 /usr/bin/python

Demo Time

Imagine the following Python script which simply prints the version of Python:

$ cat demo.py
import platform

This is script is compatible with both Python2 and Python3.

Now, let's try to execute radare2 with this initialization script, without changing the symlink of /usr/bin/python. i.e. python would point to python2.

$ readlink -f /usr/bin/python

$ r2 -q -i demo.py -

As you can see, radare2 executed the init script and printed "2.7.12".

Now, let's modify the symlink to point to python3 and test the script again:

$ sudo ln -sf /usr/bin/python3 /usr/bin/python

$ readlink -f /usr/bin/python

$ r2 -q -i demo.py -

As you requested, now python3 was executed instead of python2.

If you want python to point to python2, you can revert it back using the same command:

sudo ln -sf /usr/bin/python2.7 /usr/bin/python
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.