问题
I am having trouble installing cherrypy 3.2 on Linux machines (both on Ubuntu and Centos). I have the latest Python and Pip (version 2.7) installed on the machines. On Ubuntu, I am using $sudo pip install cherrypy. On centos, I was installing from source.
After install finished and succeeded, when importing cherrypy module, I get the error:
>>> import cherrypy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/cherrypy/__init__.py", line 62, in <module>
from cherrypy._cpcompat import urljoin as _urljoin, urlencode as _urlencode
File "/usr/local/lib/python2.7/site-packages/cherrypy/_cpcompat.py", line 184, in <module>
from http.cookies import SimpleCookie, CookieError
ImportError: No module named http.cookies
>>>
I looked up the docs and it seems http.cookies is for python 3, am I missing anything as both machine I tried are clean and never had python 3 installed?
回答1:
I ran into this today as well with a fresh install of python2.7.2 from source on centos5.6. I verified that running setup.py was using the correct subfolder (py2). In digging through _cpcompat.py it seems that it is assumed that you have SSL support, which I assumed myself. If you do not have SSL, then the following line throws an import error and imports from http, the py3.0 module.
from httplib import BadStatusLine, HTTPConnection, HTTPSConnection, IncompleteRead, NotConnected
To verify that this is what you are seeing, try the following.
from httplib import HTTPSConnection
import ssl
If you see import errors that is probably what is going on. Try enabling SSL support for python (google can help) and see if that corrects the issue.
Hope that helps : )
回答2:
Sorry about that. I'm not sure exactly what went wrong. CherryPy 3.2 supports Python 2 and 3, but to do that we opted for two different directories which setup.py switches between. It's possible that pip or some other part of your environment has gotten confused by that. You should try a simple "python setup.py install" just to be sure. Also, CherryPy 3.2.1 has re-unified the two directories, and should be released in a few days.
回答3:
You need SSL support.
- on ubuntu:
sudo apt-get install libssl-dev
. - on centos:
yum install openssl-devel
. - open
python-path/Modules/Setup.dist
, uncomment the SSL related content (make sure the SSL variable points to your SSL installation path). - recompile python,
./configure --enable-ssl & make & make install
.
来源:https://stackoverflow.com/questions/6643052/importerror-no-module-named-http-cookies-error-when-installing-cherrypy-3-2