Skip to content

Windows : ImportError: No module named pwd on util.py #356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
firm1 opened this issue Oct 2, 2015 · 8 comments · Fixed by #1314
Closed

Windows : ImportError: No module named pwd on util.py #356

firm1 opened this issue Oct 2, 2015 · 8 comments · Fixed by #1314

Comments

@firm1
Copy link
Contributor

firm1 commented Oct 2, 2015

When i try to build gitpython on Windows Server i have this error message.

File "C:\project\.tox\back\lib\site-packages\git\objects\commit.py", line 318, in create_from_tree
    committer = committer or Actor.committer(cr)
  File "C:\project\.tox\back\lib\site-packages\git\util.py", line 416, in committer
    return cls._main_actor(cls.env_committer_name, cls.env_committer_email, config_reader)
  File "C:\project\.tox\back\lib\site-packages\git\util.py", line 386, in _main_actor
    default_email = get_user_id()
  File "C:\project\.tox\back\lib\site-packages\git\util.py", line 152, in get_user_id
    return "%s@%s" % (getpass.getuser(), platform.node())
  File "c:\python27\Lib\getpass.py", line 157, in getuser
    import pwd
ImportError: No module named pwd

After search, the only solution is try this hack on utiy.py file.

Then use this :

try:
    import pwd
except ImportError:
    import winpwd as pwd
import os

def get_user_id():
    """:return: string identifying the currently active system user as name@node"""
    return "%s@%s" % (pwd.getpwuid(os.getuid()).pw_name, platform.node())

instead of

import getpass

def get_user_id():
    """:return: string identifying the currently active system user as name@node"""
    return "%s@%s" % (getpass.getuser(), platform.node())

What do you think about that ?

@Byron
Copy link
Member

Byron commented Oct 4, 2015

getpass.getuser is supposed to be a portable way of obtaining a user id, which is also used in the latest version of GitPython.

GitPython 0.3.2.1 is the first version with the fix - could it be that you are using a version older than that ?

@firm1
Copy link
Contributor Author

firm1 commented Oct 5, 2015

I don't know why, but this function is not really portable (Windows Server 2012). I use the latest release (1.0.1) of gitpython.

@firm1
Copy link
Contributor Author

firm1 commented Oct 6, 2015

On this project they are same issue with pwd.

@Byron
Copy link
Member

Byron commented Oct 15, 2015

As this seems to be an issue with the python distribution, there seems to be nothing GitPython can do. Please let me know if I have overlooked anything though,

@Byron Byron closed this as completed Oct 15, 2015
@cblegare
Copy link

If anyone is struggling with this, here is a workaround:

Since pwd is only availble on Unix, Python tries to guess the current user's username from the following environment variables:

  • LOGNAME
  • USER
  • LNAME
  • USERNAME

If for some reason none of these are set on your windows machine (it was my case when running tests on a build machine), find some way to define one of these variables in order to prevent python to try to import pwd.

@schlamar
Copy link

This is a tox issue: tox-dev/tox#1455

A workaround would be to set in tox.ini

[testenv]
passenv = USERNAME

@nmz787
Copy link

nmz787 commented May 8, 2020

tox.ini addition was the fix. Just in case search engine indexing might benefit from more keywords... I got here by searching:
ModuleNotFoundError: No module named 'pwd' "getpass.py"

and here was my traceback:

C:\Python36\lib\getpass.py:168: in getuser
    import pwd
E   ModuleNotFoundError: No module named 'pwd'

@eric-wieser
Copy link
Contributor

#1314 should fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

6 participants