Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8700259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:08:15+00:00 2026-06-13T02:08:15+00:00

I’m having trouble getting a simple Hello World app to work using Flask, MongoDB,

  • 0

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 __call__
18:21:20 web.1  |     return self.wsgi_app(environ, start_response)
18:21:20 web.1  |   File ".../venv/lib/python2.7/site-packages/flask/app.py", line 1689, in wsgi_app
18:21:20 web.1  |     response = self.make_response(self.handle_exception(e))
18:21:20 web.1  |   File ".../venv/lib/python2.7/site-packages/flask/app.py", line 1687, in wsgi_app
18:21:20 web.1  |     response = self.full_dispatch_request()
18:21:20 web.1  |   File ".../venv/lib/python2.7/site-packages/flask/app.py", line 1361, in full_dispatch_request
18:21:20 web.1  |     response = self.make_response(rv)
18:21:20 web.1  |   File ".../venv/lib/python2.7/site-packages/flask/app.py", line 1450, in make_response
18:21:20 web.1  |     rv = self.response_class.force_type(rv, request.environ)
18:21:20 web.1  |   File ".../venv/lib/python2.7/site-packages/werkzeug/wrappers.py", line 711, in force_type
18:21:20 web.1  |     response = BaseResponse(*_run_wsgi_app(response, environ))
18:21:20 web.1  |   File ".../venv/lib/python2.7/site-packages/werkzeug/test.py", line 818, in run_wsgi_app
18:21:20 web.1  |     app_iter = app(environ, start_response)
18:21:20 web.1  | TypeError: 'list' object is not callable
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:08:16+00:00Added an answer on June 13, 2026 at 2:08 am

    Try uninstalling the bson and pymongo packages and then reinstalling the pymongo package. pymongo installs its own bson package and I think you’ve overwritten it with the other bson package installation and that is probably what is causing your import error.

    FYI:

    • when you pip install pymongo it also installs bson but it does not ever print a message saying that it is install bson to your virtualenv site-packages
    • also pymongo does not list bson as a dep
    • also pip -v list does not show that bson is installed
    • those bullet points IMO have some code smell (at least print a message stating you are installing bson)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Specifically, suppose I start with the string string =hello \'i am \' me And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.