2006/7/28, Giovanni Bajo <[EMAIL PROTECTED]>:
Luis Miguel Morillas wrote:
> I want to freeze a 4Suite app (a graphical python shell with Ft lib)
> But I'm having problems when I import some Ft's modules. I can't find
> how to debug this problem. I've tried hook- files with no success :-/
> This is the last trace of a single program:
> http://livingpyxml.python-hosting.com/wiki/SingleFtPyInstaller
Hello Luis and thanks for the detailed report.
Unfortunately, 4Suite contains Python extensions (in this case,
Ft.Xml.XPath.XPathParserc which is a .pyd/.so file), whose source code
import sibling modules through PyImport_ImportModuleEx. For instance (taken
from the XPathParser.c source file):
:-/ Ok . I thoutht i was doing something wrong.
static PyObject *import_from(char *modulename, char *fromname) {
PyObject *fromlist, *name, *module;
fromlist = PyTuple_New(1);
if (fromlist == NULL) return NULL;
name = PyString_FromString(fromname);
if (name == NULL) {
Py_DECREF(fromlist);
return NULL;
}
Py_INCREF(name);
PyTuple_SET_ITEM(fromlist, 0, name);
/********** PROBLEM HERE ************/
module = PyImport_ImportModuleEx(modulename, NULL, NULL, fromlist);
Py_DECREF(fromlist);
if (module == NULL) {
Py_DECREF(name);
return NULL;
}
fromlist = PyObject_GetAttr(module, name);
Py_DECREF(module);
Py_DECREF(name);
return fromlist;
}
[...]
/* import the modules required for action routines */
/* from Ft.Xml.XPath.ParsedAbsoluteLocationPath import
ParsedAbsoluteLocationPath */
ParsedAbsoluteLocationPath =
import_from("Ft.Xml.XPath.ParsedAbsoluteLocationPath",
"ParsedAbsoluteLocationPath");
if (ParsedAbsoluteLocationPath == NULL) return;
The problem is that PyImport_ImportModuleEx, as explained in the Python
documentation, bypasses all import hooks and go directly to the Python impot
machinery. So, there is basically nothing that PyInstaller can do to
*intercept* these imports and extract the .pyc files from the internal
package. I believe that any other packager like py2exe will fail as well.
I'm working on linux version now. I want to try windows one next week,
but I think there was a problem with py2exe & setuptools.
The only solution I could think of is a runtime hook to manually import the
.pyc files *before* the C extension is loaded, so that when it tries to
import them (even through the Python machinery), it would find them already
imported in sys.modules and simply use them. Unfortunately, I believe this
is impossible because the C extension is imported in the __init__ of the
surrounding package (Ft.Xml.XPath in this case). I believe it is impossible
import a .pyc file from within a package *without* importing the package's
__init__ file first.
Would you please open a PyInstaller ticket from the website (see the FAQ
about how to login), so that I keep track of this? I'll see if I can hack up
something, but don't hold your breathe. You're possibly better off
contacting the 4Suite developers and asking them to modify their internal
imports so not to bypass the import hooks.
Ok. I'll send this mail to uche ogbuji now.
--
Giovanni Bajo
_______________________________________________
PyInstaller mailing list
[email protected]
http://lists.hpcf.upr.edu/mailman/listinfo/pyinstaller
--
Saludos,
--
Luis Miguel
_______________________________________________
PyInstaller mailing list
[email protected]
http://lists.hpcf.upr.edu/mailman/listinfo/pyinstaller