Search code examples
pythonpostgresqltornadopsycopg2momoko

Python Tornado with Postgresql using Momoko: ImportError


I am running a Python (2.7.10) Tornado (4.3) webserver that communicates with a hosted Postgres instance using Momoko (2.2.2) based on psycopg2 (2.6.1). My implementation works perfectly locally on my MAC (OSX 10.11.1), but when I push to a hosted Ubuntu (14.04.3) I get an ImportError. For example.py containing

import momoko 

yields

$ python example.py
Traceback (most recent call last):
  File "example.py", line 1, in <module>
    import momoko
  File "/usr/local/lib/python2.7/dist-packages/momoko/__init__.py", line 14, in <module>
    from .connection import Pool, Connection, connect
  File "/usr/local/lib/python2.7/dist-packages/momoko/connection.py", line 28, in <module>
    from psycopg2.extras import register_json as _psy_register_json
ImportError: cannot import name register_json

I've looked for some basic "import traps" but can't seem to find a solution. Any ideas what could be causing this?

Thanks so much folks!

UPDATE: adding the output of pip freeze:

$ pip freeze
Cheetah==2.4.4
Jinja2==2.7.2
Landscape-Client==14.12
MarkupSafe==0.18
Momoko==2.2.2
PAM==0.4.2
PyYAML==3.10
Pygments==1.6
Sphinx==1.2.2
Twisted-Core==13.2.0
Twisted-Names==13.2.0
Twisted-Web==13.2.0
apt-xapian-index==0.45
argparse==1.2.1
backports-abc==0.4
backports.ssl-match-hostname==3.4.0.2
certifi==2015.11.20.1
chardet==2.0.1
cloud-init==0.7.5
colorama==0.2.5
configobj==4.7.2
docutils==0.11
geopy==1.11.0
greenlet==0.4.5
html5lib==0.999
httplib2==0.9.1
jsonpatch==1.3
jsonpointer==1.0
motor==0.4
oauth==1.0.1
oauth2client==1.5.1
prettytable==0.7.2
psycopg2==2.6.1
pyOpenSSL==0.13
pyasn1==0.1.8
pyasn1-modules==0.0.7
pycurl==7.19.3
pymongo==2.8
pyserial==2.6
python-apt==0.9.3.5ubuntu1
python-debian==0.1.21-nmu2ubuntu2
requests==2.2.1
roman==2.0.0
rsa==3.2
singledispatch==3.4.0.3
six==1.10.0
ssh-import-id==3.21
tornado==4.3
urllib3==1.7.1
virtualenv==12.1.1
wheel==0.24.0
wsgiref==0.1.2
zope.interface==4.0.5

Solution

  • Please make sure you have a recent version of psycopg2 on your Ubuntu machine. I suggest using virtualenv and to install the latest psycopg2 there using pip.

    Ubuntu is the main testing platform for Momoko, so this must be an environment issue.