[Eclipse] Importerror no module named pwd-----getpass.getuser()

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.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
当出现"ImportError: No module named typing"错误时,这通常是因为你的代码运行在Python 2版本上,而不是Python 3版本。Python 2不支持typing模块,而typing模块在Python 3中是内置的。 解决这个问题的方法有两种: 1. 将你的代码迁移到Python 3版本上。确保你在运行代码时使用的是Python 3解释器。 2. 如果你必须在Python 2上运行代码,并且想要使用typing模块,你可以在Python 2中安装typing模块来解决这个问题。你可以通过以下步骤来安装typing模块: a. 确保你使用的是Python 2的pip,而不是Python 3的pip。你可以通过运行`python2 -m pip install typing`来安装typing模块。 b. 确保你的Python 2解释器的安装路径下安装了pip。你可以通过运行`python2 -m ensurepip`来安装pip。 c. 如果你的Python 2解释器没有安装setup-tools,你需要先安装它。你可以通过运行`python2 -m ensurepip --upgrade`来安装setup-tools。 请注意,虽然在Python 2上安装typing模块可能可以解决这个错误,但它并不能使Python 2完全支持typing模块的所有功能。因此,强烈建议将你的代码迁移到Python 3上,以获得更好的支持和稳定性。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [pip 命令行“ImportError: No Module Named Typing”](https://blog.csdn.net/Bacon_Lee/article/details/117985629)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [ImportError: No module named typing](https://blog.csdn.net/weixin_45285601/article/details/118425582)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值