Installing python librarries for use within rlm_python

Shabda Raaj shabda.raaj at bankofloyal.com
Tue Nov 1 04:49:12 CET 2016


> Your python environment is broken. Most likely, your python home is in a non-standard location

I don't think so.  "which python" gives me /usr/bin/python on the shell.

I think I have figured out the problem, and I think it is a bug in the
rlm_python code.

I put a "import sys; print sys.path" in my python file. This gives me a

['/usr/local/etc/raddb/mods-config/python']

Which is wrong, because it should have also contained the default path:

['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/home/ubuntu/.local/lib/python2.7/site-packages',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages']

This behaviour is being caused by

PySys_SetPath(path);

https://github.com/FreeRADIUS/freeradius-server/blob/ce92146386b30bd7f9f57684666554154920acce/src/modules/rlm_python/rlm_python.c#L909

Which sets the pythonpath to that hardcoded path, rather than appending to it.

I think the correct code would be along these lines

char *path, *newpath;
path=Py_GetPath();
newpath=new char[strlen(path)+4];
strcpy(newpath, path);
strcat(newpath, ":.");  // ":." for unix, or ";." for windows
PySys_SetPath(newpath);
free(newpath);

>From http://markmail.org/message/qwex6rhhqd43jg2o

Which gets the old path from Py_GetPath, and then appends to it.


More information about the Freeradius-Users mailing list