[Python-Dev] Embedded python on Win2K, import failures

Guido van Rossum guido@python.org
Sat, 12 Apr 2003 12:00:13 -0400


> [Harri]
> > Hello,
> >
> > In a few hours old CVS checkout, I'm having problems getting the
> > embedded python to work.

[Mark]
> This is true even in non-embedded Python.  Move away "_sre.pyd", and the
> interactive session shows:
> 
> 'import site' failed; use -v for traceback
> >>> import re
> >>> dir(re)
> ['__builtins__', '__doc__', '__file__', '__name__', 'engine']
> 
> Running with "-v" shows:
> 
> 'import site' failed; traceback:
> Traceback (most recent call last):
>   File "E:\src\python-cvs\lib\site.py", line 298, in ?
>     encodings._cache[enc] = encodings._unknown
> AttributeError: 'module' object has no attribute '_unknown'
> 
> So, my speculation at this point is that for some reason, site.py
> now depends on re, which depends on _sre

site.py sometimes imports distutils.util which imports re which
imports _sre.  But this is only when run from the build directory.
But there's another path that imports re, and that's from warnings,
which is imported as soon as a warning is issued (even if nothing is
printed).

> - but somehow a "stale" import is left hanging around.

That's a standard problem when module A imports B and B fails -- a
semi-complete A stays around.  Proposals to fix it have been made, but
it's tricky because deleting A isn't always the right thing to do (and
makes the failure harder to debug).

> Another strange point - executing "python", then typing "import re" is
> completely silent, as we have noted.  However, executing "python -c "import
> re" dumps an exception:
> 
> python -c "import re"
> 'import site' failed; use -v for traceback
> Traceback (most recent call last):
>   File "E:\src\python-cvs\lib\warnings.py", line 270, in ?
>     filterwarnings("ignore", category=OverflowWarning, append=1)
>   File "E:\src\python-cvs\lib\warnings.py", line 140, in filterwarnings
>     item = (action, re.compile(message, re.I), category,
> AttributeError: 'module' object has no attribute 'compile'
> 
> I'm really not sure what is going on here.  I'd suggest creating a bug at
> sf.

Have you got a $PYTHONSTRATUP?  That doesn't get executed in the
second case.

--Guido van Rossum (home page: http://www.python.org/~guido/)