import scipy.special as special
expr = (
    """(1+p[1])**(1+p[1])/special.gamma(1+p[1]) * x**p[1]/p[0]**(1+p[1]) * np.exp(-(1+p[1])*x/p[0])"""
    )

def make_func(expr):
    funcstr = """def f(x,p):
    return {e}
    """.format(e=expr)
exec(funcstr)
return f
f = make_func(expr)
print(f(1, [2, 3]))
Python/Numpy/Scipy - Converting string to mathematical function