[Tutor] 'import site' failed error

nik my.mailing.lists at noos.fr
Fri Aug 13 13:12:49 CEST 2004


Cutting my code down to a minimum still brings up the import site error. 
I now have;

demo.c:
#include "Python.h"
main(int argc, char **argv)
{
    Py_Initialize();
    Py_Finalize();  
    return 0;
}

(I've pasted the makefile at the bottom of the email, I can't remember 
where I initially took that from).

which doesn't leave much, other than something missing on my computer or 
a path problem? I'm on a fresh install of mandrake 10, with the only 
messiness being that python 2.3.3 was pre-installed, but I've built 
2.3.4 - can they exist happily side by side, or do you think I need to 
remove 2.3.3 somehow? python -V returns 2.3.3 since that version is 
first in the PATH....

Kent Johnson wrote:

> You might try to sort out whether it is your embedding that is the 
> problem or your extension code. Does your embedded interpreter work to 
> do something simple like print "Hello", when your extension is not 
> installed? Can you use your extension from the interactive interpreter?
>
> import site is something that happens when the interpreter starts up 
> so I suspect the problem is with the embedding, not the extension...
>
> Kent
>
> At 06:20 PM 8/12/2004 +0200, nik wrote:
>
>> I've drawn a blank trying to find how to get PyRun_SimpleFile to run 
>> with the verbose option - I found someone mention it on a wishlist, 
>> so perhaps it isn't possible yet.
>>
>> So instead I'm just going to ignore it for the meanwhile, since the 
>> program still seems to output correctly (the good ol' 
>> head-in-the-sand technique). However, if anyone knows how I can sort 
>> it out, please let me know.
>>
>> thanks,
>> nik
>>
>> nik wrote:
>>
>>> Hi Kent, that was a quick reply!
>>>
>>> I've embedded the interpreter in a C app, and so the python file is 
>>> called using PyRun_SimpleFile(fp, "demo2.py");
>>> so, I'm not too sure how to put the -v option in there (I'm doing 
>>> some websearching on it now).
>>>
>>> I tried a simple python file like print "hello", but it didn't come 
>>> up with the import site error, so I guess it's more to do with the 
>>> embedding or my module thingy?
>>>
>>> nik
>>>
>>> Kent Johnson wrote:
>>>
>>>> nik,
>>>>
>>>> I guess it is referring to the -v (verbose) option that you can 
>>>> pass to python when you start it up:
>>>> D:\Projects>python -v
>>>> # installing zipimport hook
>>>> import zipimport # builtin
>>>> # installed zipimport hook
>>>> # C:\Python23\lib\site.pyc matches C:\Python23\lib\site.py
>>>> import site # precompiled from C:\Python23\lib\site.pyc
>>>> # C:\Python23\lib\os.pyc matches C:\Python23\lib\os.py
>>>> import os # precompiled from C:\Python23\lib\os.pyc
>>>> etc...
>>>>
>>>> traceback is the stack trace. So this may give you more specific 
>>>> information about the location and type of failure. Give it a try 
>>>> and let us know what it says!
>>>>
>>>> Kent
>>>>
>>>> At 12:29 PM 8/12/2004 +0200, nik wrote:
>>>>
>>>>> hi,
>>>>>
>>>>> I've compiled the example in the Extending and Embedding tutorial 
>>>>> section 2.1 (creating an module with a couple of string objects), 
>>>>> and I get the error
>>>>>
>>>>> 'import site' failed; use -v for traceback
>>>>>
>>>>> even though the correct output is then printed to the screen.
>>>>>
>>>>> What does this mean?
>>>>> Do I need to post my code here (I've made a few modifications)?
>>>>> How do I do the -v for traceback, and would it be useful to me?
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>> _______________________________________________
>>> Tutor maillist  -  Tutor at python.org
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
# Makefile for embedded Python use demo.
# (This version tailored for my Red Hat Linux 6.1 setup;
# edit lines marked with XXX.)

# XXX The compiler you are using
CC=         gcc

# XXX Top of the build tree and source tree
blddir=        /home/nik/Python-2.3.4
srcdir=        /home/nik/Python-2.3.4

# Python version
VERSION=    2.3

# Compiler flags
OPT=        -ggdb
INCLUDES=    -I$(srcdir)/Include -I$(blddir)
CFLAGS=        $(OPT)
CPPFLAGS=    $(INCLUDES)

# The Python library
LIBPYTHON=    $(blddir)/libpython$(VERSION).a

# XXX edit LIBS (in particular) to match $(blddir)/Modules/Makefile
LIBS=        -lnsl -ldl -lreadline -ltermcap -lieee -lpthread -lutil
LDFLAGS=    -Xlinker -export-dynamic
SYSLIBS=    -lm
MODLIBS=   
ALLLIBS=    $(LIBPYTHON) $(MODLIBS) $(LIBS) $(SYSLIBS)

# Build the demo applications
all:        demo
demo:        demo.o
        $(CC) $(LDFLAGS) demo.o $(ALLLIBS) -o demo

# Administrative targets

test:        demo
        ./demo

clean:
        -rm -f *.o core

clobber:    clean
        -rm -f *~ @* '#'* demo

realclean:    clobber



More information about the Tutor mailing list