diff --git a/gnu/packages/weechat.scm b/gnu/packages/weechat.scm
index 48250302c32adc2539c6aaf3eb9a9e7156103137..27349ec60d27d8247c0b0f20503156e3dc05a917 100644
--- a/gnu/packages/weechat.scm
+++ b/gnu/packages/weechat.scm
@@ -87,10 +87,10 @@ (define-public weechat
                   (add-before 'build 'set-python-file-name
                     (lambda* (#:key inputs #:allow-other-keys)
                       (substitute* "src/plugins/python/weechat-python.c"
-                        (("python2_bin = .*;")
-                         (string-append "python2_bin = \""
+                        (("python2_bin = weechat_python_get_python2_bin.*;")
+                         (string-append "python2_bin = strdup (\""
                                         (assoc-ref inputs "python")
-                                        "/bin/python\";\n")))
+                                        "/bin/python\");\n")))
                       #t)))))
     (synopsis "Extensible chat client")
     (description "WeeChat (Wee Enhanced Environment for Chat) is an