I'm trying to daemonize my app and am getting the error:
out: with daemon.DaemonContext():
out: AttributeError: 'module' object has no attribute 'DaemonContext'
It looks like other people are getting this error from the module not being installed. As a newcomer to Python it's a bit confusing that there is a daemon and python-daemon package and also there's two ways of installing python packages (sudo apt-get install and sudo pip install). However, it seems like I have the package installed. I have Python 2.6 installed on Ubuntu 10.04. Any ideas?
It looks like I have the module installed:
# pip freeze
LEPL==5.0.0
MySQL-python==1.2.2
distribute==0.6.10
lockfile==0.8
matplotlib==0.99.1.1
numpy==1.3.0
pyparsing==1.5.2
python-apt==0.7.94.2ubuntu6.4
python-daemon==1.5.2
python-dateutil==1.4.1
pytz==2010b
rpy2==2.0.8
wsgiref==0.1.2
More evidence the module is installed:
$ python
>>> import daemon
>>> dir(daemon)
['DaemonContext', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '_copyright', '_license', '_url', '_version', 'daemon', 'version']
The program that produces the error is apparently using a different module named daemon
. Did you perhaps call the program itself, or another module in the same directory, daemon.py
?
If so, that will shadow the installed daemon
module.
The solution
Rename daemon.py
(and delete the daemon.pyc
file that Python will have created) and try again.
If you don't see anything shadowing daemon.py
, make your application print daemon.__file__
and see where it is being imported from.
I run on this proglem too. If I call print daemon.__file__
it prints /usr/local/lib/python2.6/dist-packages/daemon.pyc
, which is right file in wrong place, meaning that I have installed packege wrong way.
I used command "sudo pip install daemon", which installs only daemon.py file. We should use commnd
"sudo pip install python-daemon", which installs whole package. After that print daemon.__file__
prints /usr/local/lib/python2.6/dist-packages/daemon/__init__.pyc
, meaning that I have installed python-daemon -package, not just one python file daemon.py.
Confusing, but it was my own fault.
Remember to call "sudo pip uninstall daemon" before giving right installing command sudo pip uninstall python-daemon".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With