[GH-ISSUE #12] [Bug] ModuleNotFoundError: No module named 'pwd' #11

Closed
opened 2026-05-05 03:21:40 -06:00 by gitea-mirror · 3 comments
Owner

Originally created by @ghost on GitHub (Dec 23, 2021).
Original GitHub issue: https://github.com/XuehaiPan/nvitop/issues/12

Runtime Environment

  • Operating system and version: Windows 10 Build 19042.685
  • Python version: 3.8.10
  • Terminal emulator and version: PyCharm 2021.3 (Professional Edition)
  • nvitop version or commit: 0.5.2
  • python-ml-py version: 11.450.51
  • Locale: zh_CN.UTF-8

Current Behavior

When I type the nvitop in console in pycharm, it repports the error ModuleNotFoundError: No module named 'pwd'.
I have run nvitop correctly when I install it.

Expected Behavior

I want to use it for its great gui.

Context

Steps to Reproduce

1.In PyCharm IDE, switch to console and type nvitop, and enter.

Traceback

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 194, in _run_module_as_main
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "D:\PyPrj\venv\Scripts\nvitop.exe\__main__.py", line 4, in <module>
  File "d:\pyprj\venv\lib\site-packages\nvitop\cli.py", line 12, in <module>
    from nvitop.gui import Top, Device, libcurses, colored, USERNAME
  File "d:\pyprj\venv\lib\site-packages\nvitop\gui\__init__.py", line 6, in <module>
    from nvitop.gui.library import Device, libcurses, colored, USERNAME, SUPERUSER
  File "d:\pyprj\venv\lib\site-packages\nvitop\gui\library\__init__.py", line 15, in <module>
    from nvitop.gui.library.utils import (colored, cut_string, make_bar,
  File "d:\pyprj\venv\lib\site-packages\nvitop\gui\library\utils.py", line 66, in <module>
    USERNAME = getpass.getuser()
  File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\getpass.py", line 168, in getuser
    import pwd
ModuleNotFoundError: No module named 'pwd'
Originally created by @ghost on GitHub (Dec 23, 2021). Original GitHub issue: https://github.com/XuehaiPan/nvitop/issues/12 <!-- Thank you for contributing to nvitop by opening this issue. Please check through this list, so you can be as helpful as possible: 1. Was this issue already reported? Please do a quick search. 2. Maybe the problem is solved in the current master branch already? Simply clone nvitop's git repository and run ./nvitop.py to find out. 3. Provide all the relevant information, as outlined in this template. Feel free to remove any sections you don't need. --> #### Runtime Environment - Operating system and version: Windows 10 Build 19042.685 - Python version: `3.8.10` - Terminal emulator and version: `PyCharm 2021.3 (Professional Edition)` - `nvitop` version or commit: `0.5.2` - `python-ml-py` version: `11.450.51` - Locale: `zh_CN.UTF-8` #### Current Behavior When I type the `nvitop` in console in pycharm, it repports the error `ModuleNotFoundError: No module named 'pwd'`. I have run `nvitop` correctly when I install it. #### Expected Behavior I want to use it for its great gui. #### Context <!-- How has this issue affected you? What are you trying to accomplish? --> #### Steps to Reproduce 1.In PyCharm IDE, switch to `console` and type `nvitop`, and enter. #### Traceback <!-- If nvitop crashes, paste the traceback in the quotes below. --> ```pytb Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 194, in _run_module_as_main File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "D:\PyPrj\venv\Scripts\nvitop.exe\__main__.py", line 4, in <module> File "d:\pyprj\venv\lib\site-packages\nvitop\cli.py", line 12, in <module> from nvitop.gui import Top, Device, libcurses, colored, USERNAME File "d:\pyprj\venv\lib\site-packages\nvitop\gui\__init__.py", line 6, in <module> from nvitop.gui.library import Device, libcurses, colored, USERNAME, SUPERUSER File "d:\pyprj\venv\lib\site-packages\nvitop\gui\library\__init__.py", line 15, in <module> from nvitop.gui.library.utils import (colored, cut_string, make_bar, File "d:\pyprj\venv\lib\site-packages\nvitop\gui\library\utils.py", line 66, in <module> USERNAME = getpass.getuser() File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\getpass.py", line 168, in getuser import pwd ModuleNotFoundError: No module named 'pwd' ```
gitea-mirror 2026-05-05 03:21:40 -06:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@XuehaiPan commented on GitHub (Dec 23, 2021):

@qjwzmy Thanks for the report!

When I type the nvitop in console in pycharm, it repports the error ModuleNotFoundError: No module named 'pwd'.

I cannot reproduce this on my machine (Powershell / CMD / Git-Bash, and Python Console in PyCharm). Do you use a shell program other than above?

Could you try the following command in your terminal?

python -c 'import getpass; print(getpass.getuser())'

and

python -c 'import os; print(os.getlogin())'

In getpass (Python's built-in module):

def getuser():
    """Get the username from the environment or password database.

    First try various environment variables, then the password
    database.  This works on Windows as long as USERNAME is set.

    """

    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]

When your terminal emulator doesn't set USER nor USERNAME, Python will try to import pwd (Unix-like system only) to get the current user name.

<!-- gh-comment-id:1000089111 --> @XuehaiPan commented on GitHub (Dec 23, 2021): @qjwzmy Thanks for the report! > When I type the `nvitop` in console in pycharm, it repports the error `ModuleNotFoundError: No module named 'pwd'`. I cannot reproduce this on my machine (Powershell / CMD / Git-Bash, and Python Console in PyCharm). Do you use a shell program other than above? Could you try the following command in your terminal? ```bash python -c 'import getpass; print(getpass.getuser())' ``` and ```bash python -c 'import os; print(os.getlogin())' ``` ------ In `getpass` (Python's built-in module): ```python def getuser(): """Get the username from the environment or password database. First try various environment variables, then the password database. This works on Windows as long as USERNAME is set. """ 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] ``` When your terminal emulator doesn't set `USER` nor `USERNAME`, Python will try to import `pwd` (Unix-like system only) to get the current user name.
Author
Owner

@XuehaiPan commented on GitHub (Dec 23, 2021):

@qjwzmy Hi, I add a new commit to address this (56db1bf000).

Could you try to reinstall nvitop with:

pip3 install git+https://github.com/XuehaiPan/nvitop.git@dev#egg=nvitop
<!-- gh-comment-id:1000243816 --> @XuehaiPan commented on GitHub (Dec 23, 2021): @qjwzmy Hi, I add a new commit to address this (56db1bf0004aedcd88f726d05945ccf101034d23). Could you try to reinstall `nvitop` with: ```bash pip3 install git+https://github.com/XuehaiPan/nvitop.git@dev#egg=nvitop ```
Author
Owner

@XuehaiPan commented on GitHub (Dec 26, 2021):

The potential fix (56db1bf000) is now available in version 0.5.2.1 on PyPI.

Thanks for the feedback from @qjwzmy! Feel free to reopen this issue if you have any other questions.

<!-- gh-comment-id:1001115137 --> @XuehaiPan commented on GitHub (Dec 26, 2021): The potential fix (56db1bf0004aedcd88f726d05945ccf101034d23) is now available in version 0.5.2.1 on PyPI. Thanks for the feedback from @qjwzmy! Feel free to reopen this issue if you have any other questions.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/nvitop#11
No description provided.