Python27(win): import daemon, but there is an error: No module named pwd
Asked Answered
P

4

9

1) pip install daemon.

enter image description here

2) Open windows cmd and input: python, then input: import daemon the terminal show

>>> import daemon
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\daemon\__init__.py", line 42, in <module>
    from .daemon import DaemonContext
  File "C:\Python27\lib\site-packages\daemon\daemon.py", line 25, in <module>
    import pwd
ImportError: No module named pwd
>>>

3) pip install pwd

what's the problem?????

Pedrick answered 7/9, 2016 at 9:33 Comment(4)
have you tried step 2 and 3 the other way round?Bedridden
C:\Python27\Scripts>pip install pwd Collecting pwd Could not find a version that satisfies the requirement pwd (from versions: ) No matching distribution found for pwdPedrick
looks like no module named "pwd",Pedrick
Did you install it in a distribution of Python that is different to the one you are using in your project?Gentry
D
4
  1. The pwd module is a UNIX only package, it's for managing passwords.

  2. The package you are trying to install is daemon, which is an un-maintained package from 2014. There is a more recent package called python-daemon, which is well maintained and used for implementing daemons in UNIX systems. It also works with python3. Though again, this will not work on windows.

  3. If you're writing an application yourself and want to do this on windows you need to install it as a service, not a daemon this stackoverflow post is old, but still relevant.

Dissimulate answered 14/2, 2017 at 16:39 Comment(1)
python-daemon also requires pwd apparentlySlur
S
2

python-daemon (newer version) and daemon both require the pwd package, which is not available on Windows.

Your code should detect that this is not available and disable daemon mode on Windows (which isn't really a thing).

try:
    import daemon
except ImportError:
    daemon = None

Then later, you can check if daemon is None.

Slur answered 16/12, 2019 at 22:36 Comment(0)
P
0

Same thing happened to me in getpass module, it worked the first time in getpass.getuser() but then it stopped working saying

module pwd not found

I fixed it by repairing the python installation from the installer itself.

Pressley answered 18/5, 2021 at 15:34 Comment(0)
O
0

Internally they are using pwd for fetching owner's name which you can avoid by simply commenting import pwd in pebblo.pycheck the image below

Oswell answered 14/2 at 8:12 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Herrera

© 2022 - 2024 — McMap. All rights reserved.