user1035957 user1035957 - 1 month ago 10x
Python Question

python import site failed

When I execute python script, this problem occurs:

'import site' failed; use -v for traceback

so I tried again with -v option, and I can get these messages:

'import site' failed; traceback:
Traceback (most recent call last):
File "/usr/lib/python2.6/", line 513, in <module>
File "/usr/lib/python2.6/", line 495, in main
known_paths = addusersitepackages(known_paths)
File "/usr/lib/python2.6/", line 238, in addusersitepackages
USER_BASE = env_base if env_base else joinuser("~", ".local")
File "/usr/lib/python2.6/", line 225, in joinuser
return os.path.expanduser(os.path.join(*args))
File "/usr/lib/python2.6/", line 256, in expanduser
userhome = pwd.getpwuid(os.getuid()).pw_dir
KeyError: 'getpwuid(): uid not found: 65530'

How can I deal with this situations?


Looks like it expects a user with id 65530 to exist on your system, but it doesn't. And it gets that id by calling os.getuid() which returns the current user id.

Perhaps the user you're running this as has been deleted or disabled in the meantime? Check /etc/passwd for clues.

Update in light of your comment: apparently /etc/passwd does not exist inside your chroot jail. Either you can try mapping it in, or you can set the HOME environment variable to something sensible, as the code for expanduser says:

    if 'HOME' not in os.environ:
        import pwd
        userhome = pwd.getpwuid(os.getuid()).pw_dir
        userhome = os.environ['HOME']