Error when trying to use pymongo

64 views
Skip to first unread message

Yaroslav Kyrpych

unread,
Jan 30, 2015, 8:48:05 PM1/30/15
to mongod...@googlegroups.com
Hello,

I am trying to run web application using mongodb and pymongo to serve data from database.  

The error I am getting is ImportError: No module named parse. Please see below error.log from apache2 web server:

File "/var/www/FlaskApp/flaskapp.wsgi", line 12, in <module>
[:error] [pid 18824:tid 139967053518592] [client ]     from ABC import app as application
[:error] [pid 18824:tid 139967053518592] [client ]   File "var/www/FlaskApp/ABC/__init__.py", line 1, in <module>
[:error] [pid 18824:tid 139967053518592]     from pymongo import MongoClient
[:error] [pid 18824:tid 139967053518592] []   File "/var/www/FlaskApp/ABC/venv/lib/python3.4/site-packages/pymongo/__init__.py", line 92, in <module>
[:error] [pid 18824:tid 139967053518592]     from pymongo.connection import Connection
[:error] [pid 18824:tid 139967053518592]    File "/var/www/FlaskApp/ABC/venv/lib/python3.4/site-packages/pymongo/connection.py", line 39, in <module>
[:error] [pid 18824:tid 139967053518592]      from pymongo.mongo_client import MongoClient
[:error] [pid 18824:tid 139967053518592]    File "/var/www/FlaskApp/ABC/venv/lib/python3.4/site-packages/pymongo/mongo_client.py", line 46, in <module>
[:error] [pid 18824:tid 139967053518592]      from pymongo import (auth,
[:error] [pid 18824:tid 139967053518592]    File "/var/www/FlaskApp/ABC/venv/lib/python3.4/site-packages/pymongo/uri_parser.py", line 18, in <module>
[:error] [pid 18824:tid 139967053518592]     from urllib.parse import unquote_plus
[:error] [pid 18824:tid 139967053518592]  ImportError: No module named parse

I have virtual environment for Python 3.4, Flask, and pymongo. I am using mongodb 2.6.7.

Any ideas what causes issue?

Thanks,

Yaroslav

A. Jesse Jiryu Davis

unread,
Jan 30, 2015, 11:51:47 PM1/30/15
to mongod...@googlegroups.com
Yes, it looks like somehow you are running some version of Python 2, but Python3.4's site-packages are in your PYTHONPATH. Therefore you are trying to import an installation of PyMongo that has been translated with auto2to3, but it's not valid for Python 2.

Specifically, the error is that urllib.parse was introduced in Python 3:

$ python2.7
>>> from urllib.parse import unquote_plus
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named parse
>>> exit()
$ python3.4
>>> from urllib.parse import unquote_plus  # Success.
>>> exit()

Ensure you are actually using Python 3.4 to run your application.
Reply all
Reply to author
Forward
0 new messages