KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm having trouble getting a simple Hello World app to work using Flask, MongoDB, and Python. The app is bombing when trying to import from the bson module. All modules were installed successfully via pip and I'm running in a virtualenv , so I'm not sure why I'm getting the error: ImportError: cannot import name BSON Here is my sample app code: import os from flask import Flask from flask import g from flask import jsonify from flask import json from flask import request from flask import url_for from flask import redirect from flask import render_template from flask import make_response import pymongo from pymongo import Connection from bson import BSON from bson import json_util app = Flask(__name__) @app.route('/') def hello(): connection = Connection() # Get your DB db = connection.my_database # Get your collection cars = db.cars # Create some objects import datetime car = {"brand": "Ford", "model": "Mustang", "date": datetime.datetime.utcnow()} # Insert it cars.insert(car) json_docs = [json.dumps(doc, default=json_util.default) for doc in cars.find()] return json_docs if __name__ == '__main__': # Bind to PORT if defined, otherwise default to 5000. port = int(os.environ.get('PORT', 5000)) app.debug = True app.run(host='0.0.0.0', port=port) I'm not sure how to go about debugging this or if there's something I'm missing here. Edit: results of pip freeze : Flask==0.9 Jinja2==2.6 WTForms==1.0.2 Werkzeug==0.8.3 bson==0.3.3 distribute==0.6.28 mongo==0.2.0 pymongo==2.3 pytz==2012g wsgiref==0.1.2 Edit2: Removed bson and pymongo, reran pip install pymongo . Complete trace now: Traceback (most recent call last): 18:21:20 web.1 | File ".../venv/lib/python2.7/site-packages/flask/app.py", line 1701, in __ca
Tags (comma-separated)
Save Edits
Cancel