Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python import site failed

Tags:

python

import

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/site.py", line 513, in <module>
    main()
  File "/usr/lib/python2.6/site.py", line 495, in main
    known_paths = addusersitepackages(known_paths)
  File "/usr/lib/python2.6/site.py", line 238, in addusersitepackages
    USER_BASE = env_base if env_base else joinuser("~", ".local")
  File "/usr/lib/python2.6/site.py", line 225, in joinuser
    return os.path.expanduser(os.path.join(*args))
  File "/usr/lib/python2.6/posixpath.py", line 256, in expanduser
    userhome = pwd.getpwuid(os.getuid()).pw_dir
KeyError: 'getpwuid(): uid not found: 65530'

How can I deal with this situations?

like image 933
user1035957 Avatar asked May 20 '12 10:05

user1035957


1 Answers

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
    else:
        userhome = os.environ['HOME']
like image 198
Thomas Avatar answered Sep 30 '22 13:09

Thomas