I have searched for two days for the error I met with eclipse when I import matplotlib. I have installed the matplotlib module and it works well in python shell, but I can not import it in eclipse. Every time I import it, console will give me this error:
File “D:\python27\Lib\getpass.py”, line 157, in getuser import pwd ImportError: No module named pwd
Why? And what can I do to solve it?
Then I open the getpass module and find the 157 line of it
import os
for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
user = os.environ.get(name)
if user:
return user
# If this fails, the exception will "explain" why
import pwd
return pwd.getpwuid(os.getuid())[0]
And I know that on windows there is no pwd module, which is only available on unix, and basing on the code, I know when we can not get these variables ‘LOGNAME’, ‘USER’, ‘LNAME’, ‘USERNAME’, the import pwd will run.
It means that in the python shell, we can get one of these numbers but none can be got in eclipse. Why? Then I try
import getpass
getpass.getuser()
in the shell, it gives me the login name of my computer. But it cannot work in eclipse.
So I get the point, we cannot get the USERNAME in eclipse. Then I think: can i set it in eclipse? The answer is: Yes, we can set USERNAME in eclipse to solve this problem.
本文探讨了在Eclipse环境中遇到的matplotlib导入失败问题,详细分析了错误信息并提供了有效的解决方案,即设置USERNAME变量来避免因无法找到该变量而导致的错误。
2157





