python导入站点失败 [英] python import site failed
问题描述
当我执行python脚本时,会出现此问题:
When I execute python script, this problem occurs:
'import site' failed; use -v for traceback
所以我再次尝试使用-v选项,我可以得到以下消息:
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'
如何处理这种情况?
推荐答案
看起来它希望ID为65530的用户存在于您的系统上,但实际上并不存在.并通过调用os.getuid()
来获取该ID,该ID返回当前用户ID.
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.
也许您正在运行的用户同时已被删除或禁用?检查/etc/passwd
的线索.
Perhaps the user you're running this as has been deleted or disabled in the meantime? Check /etc/passwd
for clues.
根据您的评论进行更新:显然/etc/passwd
在您的chroot监狱中不存在.您可以尝试将其映射到其中,也可以将HOME
环境变量设置为明智的设置,如expanduser
的代码所述:
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']
这篇关于python导入站点失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!